A wrapper class for talking to Axeda from MBED devices. Uses HTTPClient and MbedJSONValue classes.
Dependents: axeda_wrapper_dev MTS_Axeda_Example
AxedaWrapper simplifies pushing data to Axeda's cloud.
Uses HTTPClient and MbedJSONValue libs:
http://mbed.org/users/donatien/code/HTTPClient/
http://mbed.org/users/samux/code/MbedJSONValue/
tests/test_AxedaWrapper.h@6:aa0594410aa9, 2014-01-04 (annotated)
- Committer:
- mfiore
- Date:
- Sat Jan 04 08:00:38 2014 +0000
- Revision:
- 6:aa0594410aa9
- Parent:
- 3:134410324a6a
shorten HTTPClient timeout to 5 seconds
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mfiore | 2:99baa98f84a3 | 1 | #ifndef TEST_AXEDAWRAPPER_H |
mfiore | 2:99baa98f84a3 | 2 | #define TEST_AXEDAWRAPPER_H |
mfiore | 2:99baa98f84a3 | 3 | |
mfiore | 2:99baa98f84a3 | 4 | #include "mbed.h" |
mfiore | 2:99baa98f84a3 | 5 | #include "AxedaWrapper.h" |
mfiore | 2:99baa98f84a3 | 6 | |
mfiore | 2:99baa98f84a3 | 7 | // test push(), toString(), clear(), and size() functions |
mfiore | 2:99baa98f84a3 | 8 | int testAxedaWrapper() { |
sgodinez | 3:134410324a6a | 9 | using namespace mts; |
sgodinez | 3:134410324a6a | 10 | |
mfiore | 2:99baa98f84a3 | 11 | int failed = 0; |
mfiore | 2:99baa98f84a3 | 12 | std::string data; |
mfiore | 2:99baa98f84a3 | 13 | std::string json_data; |
mfiore | 2:99baa98f84a3 | 14 | MbedJSONValue json; |
mfiore | 2:99baa98f84a3 | 15 | |
mfiore | 2:99baa98f84a3 | 16 | std::string serial = "bogus-001"; |
mfiore | 2:99baa98f84a3 | 17 | AxedaWrapper* client = new AxedaWrapper(serial); |
mfiore | 2:99baa98f84a3 | 18 | |
mfiore | 2:99baa98f84a3 | 19 | // test size() when map is empty |
mfiore | 2:99baa98f84a3 | 20 | if (client->size() != 0) { |
mfiore | 2:99baa98f84a3 | 21 | printf("size() failed - empty\n\r"); |
mfiore | 2:99baa98f84a3 | 22 | failed++; |
mfiore | 2:99baa98f84a3 | 23 | } |
mfiore | 2:99baa98f84a3 | 24 | |
mfiore | 2:99baa98f84a3 | 25 | // test toString() when map is empty |
mfiore | 2:99baa98f84a3 | 26 | data = client->toString(); |
mfiore | 2:99baa98f84a3 | 27 | if (data != "{}") { |
mfiore | 2:99baa98f84a3 | 28 | printf("toString() failed - empty\n\r"); |
mfiore | 2:99baa98f84a3 | 29 | failed++; |
mfiore | 2:99baa98f84a3 | 30 | } |
mfiore | 2:99baa98f84a3 | 31 | |
mfiore | 2:99baa98f84a3 | 32 | // test clear() when map is empty |
mfiore | 2:99baa98f84a3 | 33 | client->clear(); |
mfiore | 2:99baa98f84a3 | 34 | data = client->toString(); |
mfiore | 2:99baa98f84a3 | 35 | if (data != "{}") { |
mfiore | 2:99baa98f84a3 | 36 | printf("clear() failed - empty\n\r"); |
mfiore | 2:99baa98f84a3 | 37 | failed++; |
mfiore | 2:99baa98f84a3 | 38 | } |
mfiore | 2:99baa98f84a3 | 39 | |
mfiore | 2:99baa98f84a3 | 40 | // test different push() methods (and toString()) |
mfiore | 2:99baa98f84a3 | 41 | std::string key1 = "key1"; |
mfiore | 2:99baa98f84a3 | 42 | std::string value1 = "value1"; |
mfiore | 2:99baa98f84a3 | 43 | client->push(key1, value1); |
mfiore | 2:99baa98f84a3 | 44 | json[key1] = value1; |
mfiore | 2:99baa98f84a3 | 45 | |
mfiore | 2:99baa98f84a3 | 46 | const char* key2 = "key2"; |
mfiore | 2:99baa98f84a3 | 47 | const char* value2 = "value2"; |
mfiore | 2:99baa98f84a3 | 48 | client->push(key2, value2); |
mfiore | 2:99baa98f84a3 | 49 | json[key2] = value2; |
mfiore | 2:99baa98f84a3 | 50 | |
mfiore | 2:99baa98f84a3 | 51 | std::string key3 = "key3"; |
mfiore | 2:99baa98f84a3 | 52 | int value3 = 15; |
mfiore | 2:99baa98f84a3 | 53 | client->push(key3, value3); |
mfiore | 2:99baa98f84a3 | 54 | json[key3] = value3; |
mfiore | 2:99baa98f84a3 | 55 | |
mfiore | 2:99baa98f84a3 | 56 | const char* key4 = "key4"; |
mfiore | 2:99baa98f84a3 | 57 | int value4 = 30; |
mfiore | 2:99baa98f84a3 | 58 | client->push(key4, value4); |
mfiore | 2:99baa98f84a3 | 59 | json[key4] = value4; |
mfiore | 2:99baa98f84a3 | 60 | |
mfiore | 2:99baa98f84a3 | 61 | std::string key5 = "key5"; |
mfiore | 2:99baa98f84a3 | 62 | double value5 = 87.6; |
mfiore | 2:99baa98f84a3 | 63 | client->push(key5, value5); |
mfiore | 2:99baa98f84a3 | 64 | json[key5] = value5; |
mfiore | 2:99baa98f84a3 | 65 | |
mfiore | 2:99baa98f84a3 | 66 | const char* key6 = "key6"; |
mfiore | 2:99baa98f84a3 | 67 | double value6 = 1000.756; |
mfiore | 2:99baa98f84a3 | 68 | client->push(key6, value6); |
mfiore | 2:99baa98f84a3 | 69 | json[key6] = value6; |
mfiore | 2:99baa98f84a3 | 70 | |
mfiore | 2:99baa98f84a3 | 71 | std::string key7 = "key7"; |
mfiore | 2:99baa98f84a3 | 72 | bool value7 = true; |
mfiore | 2:99baa98f84a3 | 73 | client->push(key7, value7); |
mfiore | 2:99baa98f84a3 | 74 | json[key7] = value7; |
mfiore | 2:99baa98f84a3 | 75 | |
mfiore | 2:99baa98f84a3 | 76 | std::string key8 = "key8"; |
mfiore | 2:99baa98f84a3 | 77 | bool value8 = false; |
mfiore | 2:99baa98f84a3 | 78 | client->push(key8, value8); |
mfiore | 2:99baa98f84a3 | 79 | json[key8] = value8; |
mfiore | 2:99baa98f84a3 | 80 | |
mfiore | 2:99baa98f84a3 | 81 | data = client->toString(); |
mfiore | 2:99baa98f84a3 | 82 | json_data = json.serialize(); |
mfiore | 2:99baa98f84a3 | 83 | if (data != json_data) { |
mfiore | 2:99baa98f84a3 | 84 | printf("push() failed\n\r"); |
mfiore | 2:99baa98f84a3 | 85 | printf("data: %s\n\r", data.c_str()); |
mfiore | 2:99baa98f84a3 | 86 | printf("json_data: %s\n\r", json_data.c_str()); |
mfiore | 2:99baa98f84a3 | 87 | failed ++; |
mfiore | 2:99baa98f84a3 | 88 | } |
mfiore | 2:99baa98f84a3 | 89 | |
mfiore | 2:99baa98f84a3 | 90 | // test size() with non-empty map |
mfiore | 2:99baa98f84a3 | 91 | if (client->size() != 8) { |
mfiore | 2:99baa98f84a3 | 92 | printf("size() failed - not empty\n\r"); |
mfiore | 2:99baa98f84a3 | 93 | failed++; |
mfiore | 2:99baa98f84a3 | 94 | } |
mfiore | 2:99baa98f84a3 | 95 | |
mfiore | 2:99baa98f84a3 | 96 | // test clear() when map is not empty |
mfiore | 2:99baa98f84a3 | 97 | client->clear(); |
mfiore | 2:99baa98f84a3 | 98 | data = client->toString(); |
mfiore | 2:99baa98f84a3 | 99 | if (data != "{}" || client->size() != 0) { |
mfiore | 2:99baa98f84a3 | 100 | printf("clear() failed - not empty\n\r"); |
mfiore | 2:99baa98f84a3 | 101 | failed++; |
mfiore | 2:99baa98f84a3 | 102 | } |
mfiore | 2:99baa98f84a3 | 103 | |
mfiore | 2:99baa98f84a3 | 104 | delete client; |
mfiore | 2:99baa98f84a3 | 105 | return failed; |
mfiore | 2:99baa98f84a3 | 106 | } |
mfiore | 2:99baa98f84a3 | 107 | |
mfiore | 2:99baa98f84a3 | 108 | #endif |