Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: axeda_wrapper_dev MTS_Axeda_Example
test_AxedaWrapper.h
00001 #ifndef TEST_AXEDAWRAPPER_H 00002 #define TEST_AXEDAWRAPPER_H 00003 00004 #include "mbed.h" 00005 #include "AxedaWrapper.h" 00006 00007 // test push(), toString(), clear(), and size() functions 00008 int testAxedaWrapper() { 00009 using namespace mts; 00010 00011 int failed = 0; 00012 std::string data; 00013 std::string json_data; 00014 MbedJSONValue json; 00015 00016 std::string serial = "bogus-001"; 00017 AxedaWrapper* client = new AxedaWrapper(serial); 00018 00019 // test size() when map is empty 00020 if (client->size() != 0) { 00021 printf("size() failed - empty\n\r"); 00022 failed++; 00023 } 00024 00025 // test toString() when map is empty 00026 data = client->toString(); 00027 if (data != "{}") { 00028 printf("toString() failed - empty\n\r"); 00029 failed++; 00030 } 00031 00032 // test clear() when map is empty 00033 client->clear(); 00034 data = client->toString(); 00035 if (data != "{}") { 00036 printf("clear() failed - empty\n\r"); 00037 failed++; 00038 } 00039 00040 // test different push() methods (and toString()) 00041 std::string key1 = "key1"; 00042 std::string value1 = "value1"; 00043 client->push(key1, value1); 00044 json[key1] = value1; 00045 00046 const char* key2 = "key2"; 00047 const char* value2 = "value2"; 00048 client->push(key2, value2); 00049 json[key2] = value2; 00050 00051 std::string key3 = "key3"; 00052 int value3 = 15; 00053 client->push(key3, value3); 00054 json[key3] = value3; 00055 00056 const char* key4 = "key4"; 00057 int value4 = 30; 00058 client->push(key4, value4); 00059 json[key4] = value4; 00060 00061 std::string key5 = "key5"; 00062 double value5 = 87.6; 00063 client->push(key5, value5); 00064 json[key5] = value5; 00065 00066 const char* key6 = "key6"; 00067 double value6 = 1000.756; 00068 client->push(key6, value6); 00069 json[key6] = value6; 00070 00071 std::string key7 = "key7"; 00072 bool value7 = true; 00073 client->push(key7, value7); 00074 json[key7] = value7; 00075 00076 std::string key8 = "key8"; 00077 bool value8 = false; 00078 client->push(key8, value8); 00079 json[key8] = value8; 00080 00081 data = client->toString(); 00082 json_data = json.serialize(); 00083 if (data != json_data) { 00084 printf("push() failed\n\r"); 00085 printf("data: %s\n\r", data.c_str()); 00086 printf("json_data: %s\n\r", json_data.c_str()); 00087 failed ++; 00088 } 00089 00090 // test size() with non-empty map 00091 if (client->size() != 8) { 00092 printf("size() failed - not empty\n\r"); 00093 failed++; 00094 } 00095 00096 // test clear() when map is not empty 00097 client->clear(); 00098 data = client->toString(); 00099 if (data != "{}" || client->size() != 0) { 00100 printf("clear() failed - not empty\n\r"); 00101 failed++; 00102 } 00103 00104 delete client; 00105 return failed; 00106 } 00107 00108 #endif
Generated on Thu Jul 14 2022 15:08:08 by
1.7.2