Adding files to initialize, update, and read key-value (to be used together with...
[iotcloud.git] / version2 / src / C / Read.C
diff --git a/version2/src/C/Read.C b/version2/src/C/Read.C
new file mode 100644 (file)
index 0000000..eff53aa
--- /dev/null
@@ -0,0 +1,62 @@
+#include "Table.h"
+#include "IoTString.h"
+#include "TimingSingleton.h"
+#include "TransactionStatus.h"
+
+#define NUMBER_OF_TESTS 1
+#define MACHINE_ID 371
+
+int main(int numargs, char ** args) {
+       TimingSingleton * timer = TimingSingleton_getInstance();
+
+       bool foundError = false;
+       Vector<TransactionStatus *> * transStatusList = new Vector<TransactionStatus *>();
+
+       // Setup the 2 clients
+       IoTString *baseurl = new IoTString("http://dc-6.calit2.uci.edu/test.iotcloud/");
+       IoTString * password = new IoTString("reallysecret");
+       Table * t1 = new Table(baseurl, password, MACHINE_ID, -1);
+       //t1->initTable();
+       t1->rebuild();
+       printf("T1 Ready\n");
+
+       baseurl->releaseRef();
+       password->releaseRef();
+
+       printf("Checking Key-Values...\n");
+       char buffer[80];
+       sprintf(buffer, "sensor0");
+       IoTString * iKeyA = new IoTString(buffer);
+       IoTString *testValA1 = t1->getCommitted(iKeyA);
+       
+       if (testValA1 == NULL) {
+               printf("\n\nKEY-VALUE A is NULL!\n\n");
+               foundError = true;
+       } else {
+               printf("Printing value... ");
+               testValA1->print();
+               printf("\n\n");
+       }
+
+       iKeyA->releaseRef();
+       testValA1->releaseRef();
+
+       for (uint i = 0; i < transStatusList->size(); i++) {
+               TransactionStatus * status = transStatusList->get(i);
+               if (status->getStatus() != TransactionStatus_StatusCommitted) {
+                       foundError = true;
+                       printf("Status error\n");
+               }
+               delete status;
+       }
+       
+       if (foundError) {
+               printf("Found Errors...\n");
+       } else {
+               printf("No Errors Found...\n");
+       }
+
+       delete transStatusList;
+       delete t1;
+}
+