Lots of progress on indefinite lengths; refactor decoder to get of weird semi-recursion
diff --git a/test/basic_test.c b/test/basic_test.c
index 508c6fd..8241302 100644
--- a/test/basic_test.c
+++ b/test/basic_test.c
@@ -138,3 +138,88 @@
 
 
 
+static const uint8_t pIndefiniteLenString[] = {
+   0x81, // Array of length one
+   0x7f, // text string marked with indefinite length
+      0x65, 0x73, 0x74, 0x72, 0x65, 0x61, // first segment
+      0x64, 0x6d, 0x69, 0x6e, 0x67, // second segment
+   0xff // ending break
+};
+
+static const uint8_t pIndefiniteArray[] = {0x9f, 0x01, 0x82, 0x02, 0x03, 0xff};
+
+//0x9f018202039f0405ffff
+
+int indefinite_length_decode_test() {
+    UsefulBufC IndefLen = UsefulBuf_FromByteArrayLiteral(pIndefiniteArray);
+    
+    
+    // Decode it and see if it is OK
+   UsefulBuf_MakeStackUB(MemPool, 200);
+    QCBORDecodeContext DC;
+    QCBORItem Item;
+    QCBORDecode_Init(&DC, IndefLen, QCBOR_DECODE_MODE_NORMAL);
+   
+   QCBORDecode_SetMemPool(&DC, MemPool, false);
+
+   
+    QCBORDecode_GetNext(&DC, &Item);
+    if(Item.uDataType != QCBOR_TYPE_ARRAY) {
+        return -1;
+    }
+
+   QCBORDecode_GetNext(&DC, &Item);
+   if(Item.uDataType != QCBOR_TYPE_INT64) {
+      return -1;
+   }
+   
+    QCBORDecode_GetNext(&DC, &Item);
+    if(Item.uDataType != QCBOR_TYPE_ARRAY) {
+        return -1;
+    }
+    
+    QCBORDecode_GetNext(&DC, &Item);
+    if(Item.uDataType != QCBOR_TYPE_INT64) {
+        return -1;
+    }
+    
+    QCBORDecode_GetNext(&DC, &Item);
+    if(Item.uDataType != QCBOR_TYPE_INT64) {
+        return -1;
+    }
+   
+   if(QCBORDecode_Finish(&DC)) {
+      return -2;
+   }
+    
+    return 0;
+}
+
+int indefinite_length_decode_string_test() {
+   UsefulBufC IndefLen = UsefulBuf_FromByteArrayLiteral(pIndefiniteLenString);
+   
+   
+   // Decode it and see if it is OK
+   QCBORDecodeContext DC;
+   QCBORItem Item;
+   UsefulBuf_MakeStackUB(MemPool, 200);
+
+   QCBORDecode_Init(&DC, IndefLen, QCBOR_DECODE_MODE_NORMAL);
+   
+   QCBORDecode_SetMemPool(&DC,  MemPool, false);
+
+   
+   QCBORDecode_GetNext(&DC, &Item);
+   if(Item.uDataType != QCBOR_TYPE_ARRAY) {
+      return -1;
+   }
+   
+   QCBORDecode_GetNext(&DC, &Item);
+   if(Item.uDataType != QCBOR_TYPE_TEXT_STRING) {
+      return -1;
+   }
+   
+   return 0;
+}
+
+
diff --git a/test/basic_test.h b/test/basic_test.h
index cde44ba..6f3dd66 100644
--- a/test/basic_test.h
+++ b/test/basic_test.h
@@ -31,4 +31,7 @@
 
 int basic_test_one(void);
 
+int indefinite_length_decode_test(void);
+int indefinite_length_decode_string_test(void);
+
 #endif /* basic_test_h */
diff --git a/test/run_tests.c b/test/run_tests.c
index 013b6e5..c3379f3 100644
--- a/test/run_tests.c
+++ b/test/run_tests.c
@@ -93,6 +93,8 @@
 } test_entry;
 
 test_entry s_tests[] = {
+    TEST_ENTRY(indefinite_length_decode_string_test),
+    TEST_ENTRY(indefinite_length_decode_test),
     TEST_ENTRY(basic_test_one),
     TEST_ENTRY(half_precision_encode_basic),
     TEST_ENTRY(half_precision_decode_basic),
diff --git a/test/run_tests.h b/test/run_tests.h
index 013b6e5..4338dce 100644
--- a/test/run_tests.h
+++ b/test/run_tests.h
@@ -28,126 +28,6 @@
  ==============================================================================*/
 //  Created by Laurence Lundblade on 9/30/18.
 
+typedef int (*outputstring)(const char *szString, void *ctx);
 
-#include "run_tests.h"
-#include "UsefulBuf.h"
-#include <stdbool.h>
-
-#include "half_precision_test.h"
-#include "basic_test.h"
-#include "bstrwrap_tests.h"
-
-// Used to test the test runner
-int fail_test()
-{
-    return -44;
-}
-
-
-/*
- Convert a number up to 999999999 to a string. This is so sprintf doesn't
- have to be linked in so as to minimized dependencies even in test code.
- 
- This function does pointer math. TODO: test this.
- */
-const char *NumToString(int32_t nNum, UsefulBuf StringMem)
-{
-    const uint32_t uMax = 1000000000;
-    
-    UsefulOutBuf OutBuf;
-    UsefulOutBuf_Init(&OutBuf, StringMem);
-    
-    if(nNum < 0) {
-        UsefulOutBuf_AppendByte(&OutBuf, '-');
-        nNum = -nNum;
-    }
-    if(nNum > uMax-1) {
-        return "XXX";
-    }
-    
-    bool bDidSomeOutput = false;
-    for(int n = uMax; n > 0; n/=10) {
-        int x = nNum/n;
-        if(x || bDidSomeOutput){
-            bDidSomeOutput = true;
-            UsefulOutBuf_AppendByte(&OutBuf, '0' + x);
-            nNum -= x * n;
-        }
-    }
-    if(!bDidSomeOutput){
-        UsefulOutBuf_AppendByte(&OutBuf, '0');
-    }
-    UsefulOutBuf_AppendByte(&OutBuf, '\0');
-    
-    return UsefulOutBuf_GetError(&OutBuf) ? "" : StringMem.ptr;
-}
-
-
-
-typedef int (test_fun_t)(void);
-
-#define TEST_ENTRY(test_name)  {#test_name, test_name}
-typedef struct {
-    const char *szTestName;
-    test_fun_t  *test_fun;
-} test_entry;
-
-test_entry s_tests[] = {
-    TEST_ENTRY(basic_test_one),
-    TEST_ENTRY(half_precision_encode_basic),
-    TEST_ENTRY(half_precision_decode_basic),
-    TEST_ENTRY(half_precision_to_float_transitive_test),
-    TEST_ENTRY(double_as_smallest_encode_basic),
-    TEST_ENTRY(half_precision_to_float_vs_rfc_test),
-    TEST_ENTRY(bstrwraptest),
-    TEST_ENTRY(bstr_wrap_error_test),
-    TEST_ENTRY(bstr_wrap_nest_test),
-    TEST_ENTRY(cose_sign1_tbs_test),
-    //TEST_ENTRY(fail_test),
-};
-
-
-int run_tests(outputstring output, void *poutCtx, int *pNumTestsRun)
-{
-    int nTestsFailed = 0;
-    int nTestsRun = 0;
-    UsefulBuf_MakeStackUB(StringStorage, 5);
-    
-    test_entry *t;
-    const test_entry *s_tests_end = s_tests + sizeof(s_tests)/sizeof(test_entry);
-    
-    for(t = s_tests; t < s_tests_end; t++) {
-        int x = (t->test_fun)();
-        nTestsRun++;
-        if(output) {
-            (*output)(t->szTestName, poutCtx);
-        }
-        
-        if(x) {
-            if(output) {
-                (*output)(" FAILED (returned ", poutCtx);
-                (*output)(NumToString(x, StringStorage), poutCtx);
-                (*output)(")\n", poutCtx);
-            }
-            nTestsFailed++;
-        } else {
-            if(output) {
-                (*output)( " PASSED\n", poutCtx);
-            }
-        }
-    }
-    
-    if(pNumTestsRun) {
-        *pNumTestsRun = nTestsRun;
-    }
-    
-    if(output) {
-        (*output)( "SUMMARY: ", poutCtx);
-        (*output)( NumToString(nTestsRun, StringStorage), poutCtx);
-        (*output)( " tests run; ", poutCtx);
-        (*output)( NumToString(nTestsFailed, StringStorage), poutCtx);
-        (*output)( " tests failed\n", poutCtx);
-    }
-    
-    return nTestsFailed;
-}
+int run_tests(outputstring output, void *poutCtx, int *pNumTestsRun);