2 * Basic tests for IoTCloud library.
3 * @author Brian Demsky <bdemsky@uci.edu>
9 #include "TimingSingleton.h"
10 #include "TransactionStatus.h"
12 #define NUMBER_OF_TESTS 2
14 TimingSingleton *timer;
16 MyVector<TransactionStatus *> * transStatusList;
20 // TODO: This test uses the Serial library
21 // Please install "screen" on your machine and run
22 // it on the serial port right after flashing the
23 // firmware onto the Particle board.
24 // e.g. sudo screen /dev/ttyACM0
26 timer = TimingSingleton_getInstance();
28 transStatusList = new MyVector<TransactionStatus *>();
29 IoTString *baseurl = new IoTString("http://dc-6.calit2.uci.edu/test.iotcloud/");
30 IoTString * password = new IoTString("reallysecret");
31 t1 = new Table(baseurl, password, 321, -1);
33 Serial.println("Finished table init...");
34 baseurl->releaseRef();
35 password->releaseRef();
38 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
40 sprintf(buffer, "a%d", i);
41 IoTString *ia = new IoTString(buffer);
42 sprintf(buffer, "b%d", i);
43 IoTString *ib = new IoTString(buffer);
44 t1->createNewKey(ia, 321);
45 t1->createNewKey(ib, 321);
49 Serial.println("Finished key generation...");
54 // Do Updates for the keys
55 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
57 sprintf(buffer, "a%d", i);
58 IoTString * iKeyA = new IoTString(buffer);
59 IoTString * iValueA = new IoTString(buffer);
61 sprintf(buffer, "b%d", i);
62 IoTString * iKeyB = new IoTString(buffer);
63 IoTString * iValueB = new IoTString(buffer);
65 t1->startTransaction();
66 t1->put(iKeyA, iValueA);
67 transStatusList->add(t1->commitTransaction());
69 iValueA->releaseRef();
71 t1->startTransaction();
72 t1->put(iKeyB, iValueB);
73 transStatusList->add(t1->commitTransaction());
75 iValueB->releaseRef();
77 Serial.println("Added new transaction: ");
85 Serial.println("Updated table...");
87 for (int i = 0; i < NUMBER_OF_TESTS; i++) {
89 sprintf(buffer, "a%d", i);
90 IoTString * iKeyA = new IoTString(buffer);
91 IoTString * iValueA = new IoTString(buffer);
93 sprintf(buffer, "b%d", i);
94 IoTString * iKeyB = new IoTString(buffer);
95 IoTString * iValueB = new IoTString(buffer);
97 IoTString *testValA1 = t1->getCommitted(iKeyA);
98 IoTString *testValB1 = t1->getCommitted(iKeyB);
100 if ((testValA1 == NULL) || (testValA1->equals(iValueA) == false)) {
101 Serial.println("Key-Value t1 incorrect: keyA");
105 if ((testValB1 == NULL) || (testValB1->equals(iValueB) == false)) {
106 Serial.println("Key-Value t1 incorrect: keyB");
111 iValueA->releaseRef();
113 iValueB->releaseRef();
114 testValA1->releaseRef();
115 testValB1->releaseRef();
118 for (uint i = 0; i < transStatusList->size(); i++) {
119 TransactionStatus * status = transStatusList->get(i);
120 if (status->getStatus() != TransactionStatus_StatusCommitted) {
122 Serial.println("Status error");
128 Serial.println("Found Errors...");
131 delete transStatusList;
134 Serial.println("Process done... now waiting...");