gbathree.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. // ArduinoJson - https://arduinojson.org
  2. // Copyright © 2014-2022, Benoit BLANCHON
  3. // MIT License
  4. #include <ArduinoJson.h>
  5. #include <catch.hpp>
  6. TEST_CASE("Gbathree") {
  7. DynamicJsonDocument doc(4096);
  8. DeserializationError error = deserializeJson(
  9. doc,
  10. "{\"protocol_name\":\"fluorescence\",\"repeats\":1,\"wait\":0,"
  11. "\"averages\":1,\"measurements\":3,\"meas2_light\":15,\"meas1_"
  12. "baseline\":0,\"act_light\":20,\"pulsesize\":25,\"pulsedistance\":"
  13. "10000,\"actintensity1\":50,\"actintensity2\":255,\"measintensity\":"
  14. "255,\"calintensity\":255,\"pulses\":[50,50,50],\"act\":[2,1,2,2],"
  15. "\"red\":[2,2,2,2],\"detectors\":[[34,34,34,34],[34,34,34,34],[34,"
  16. "34,34,34],[34,34,34,34]],\"alta\":[2,2,2,2],\"altb\":[2,2,2,2],"
  17. "\"measlights\":[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,"
  18. "15,15]],\"measlights2\":[[15,15,15,15],[15,15,15,15],[15,15,15,15],"
  19. "[15,15,15,15]],\"altc\":[2,2,2,2],\"altd\":[2,2,2,2]}");
  20. JsonObject root = doc.as<JsonObject>();
  21. SECTION("Success") {
  22. REQUIRE(error == DeserializationError::Ok);
  23. }
  24. SECTION("ProtocolName") {
  25. REQUIRE("fluorescence" == root["protocol_name"]);
  26. }
  27. SECTION("Repeats") {
  28. REQUIRE(1 == root["repeats"]);
  29. }
  30. SECTION("Wait") {
  31. REQUIRE(0 == root["wait"]);
  32. }
  33. SECTION("Measurements") {
  34. REQUIRE(3 == root["measurements"]);
  35. }
  36. SECTION("Meas2_Light") {
  37. REQUIRE(15 == root["meas2_light"]);
  38. }
  39. SECTION("Meas1_Baseline") {
  40. REQUIRE(0 == root["meas1_baseline"]);
  41. }
  42. SECTION("Act_Light") {
  43. REQUIRE(20 == root["act_light"]);
  44. }
  45. SECTION("Pulsesize") {
  46. REQUIRE(25 == root["pulsesize"]);
  47. }
  48. SECTION("Pulsedistance") {
  49. REQUIRE(10000 == root["pulsedistance"]);
  50. }
  51. SECTION("Actintensity1") {
  52. REQUIRE(50 == root["actintensity1"]);
  53. }
  54. SECTION("Actintensity2") {
  55. REQUIRE(255 == root["actintensity2"]);
  56. }
  57. SECTION("Measintensity") {
  58. REQUIRE(255 == root["measintensity"]);
  59. }
  60. SECTION("Calintensity") {
  61. REQUIRE(255 == root["calintensity"]);
  62. }
  63. SECTION("Pulses") {
  64. // "pulses":[50,50,50]
  65. JsonArray array = root["pulses"];
  66. REQUIRE(array.isNull() == false);
  67. REQUIRE(3 == array.size());
  68. for (size_t i = 0; i < 3; i++) {
  69. REQUIRE(50 == array[i]);
  70. }
  71. }
  72. SECTION("Act") {
  73. // "act":[2,1,2,2]
  74. JsonArray array = root["act"];
  75. REQUIRE(array.isNull() == false);
  76. REQUIRE(4 == array.size());
  77. REQUIRE(2 == array[0]);
  78. REQUIRE(1 == array[1]);
  79. REQUIRE(2 == array[2]);
  80. REQUIRE(2 == array[3]);
  81. }
  82. SECTION("Detectors") {
  83. // "detectors":[[34,34,34,34],[34,34,34,34],[34,34,34,34],[34,34,34,34]]
  84. JsonArray array = root["detectors"];
  85. REQUIRE(array.isNull() == false);
  86. REQUIRE(4 == array.size());
  87. for (size_t i = 0; i < 4; i++) {
  88. JsonArray nestedArray = array[i];
  89. REQUIRE(4 == nestedArray.size());
  90. for (size_t j = 0; j < 4; j++) {
  91. REQUIRE(34 == nestedArray[j]);
  92. }
  93. }
  94. }
  95. SECTION("Alta") {
  96. // alta:[2,2,2,2]
  97. JsonArray array = root["alta"];
  98. REQUIRE(array.isNull() == false);
  99. REQUIRE(4 == array.size());
  100. for (size_t i = 0; i < 4; i++) {
  101. REQUIRE(2 == array[i]);
  102. }
  103. }
  104. SECTION("Altb") {
  105. // altb:[2,2,2,2]
  106. JsonArray array = root["altb"];
  107. REQUIRE(array.isNull() == false);
  108. REQUIRE(4 == array.size());
  109. for (size_t i = 0; i < 4; i++) {
  110. REQUIRE(2 == array[i]);
  111. }
  112. }
  113. SECTION("Measlights") {
  114. // "measlights":[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]]
  115. JsonArray array = root["measlights"];
  116. REQUIRE(array.isNull() == false);
  117. REQUIRE(4 == array.size());
  118. for (size_t i = 0; i < 4; i++) {
  119. JsonArray nestedArray = array[i];
  120. REQUIRE(4 == nestedArray.size());
  121. for (size_t j = 0; j < 4; j++) {
  122. REQUIRE(15 == nestedArray[j]);
  123. }
  124. }
  125. }
  126. SECTION("Measlights2") {
  127. // "measlights2":[[15,15,15,15],[15,15,15,15],[15,15,15,15],[15,15,15,15]]
  128. JsonArray array = root["measlights2"];
  129. REQUIRE(array.isNull() == false);
  130. REQUIRE(4 == array.size());
  131. for (size_t i = 0; i < 4; i++) {
  132. JsonArray nestedArray = array[i];
  133. REQUIRE(4 == nestedArray.size());
  134. for (size_t j = 0; j < 4; j++) {
  135. REQUIRE(15 == nestedArray[j]);
  136. }
  137. }
  138. }
  139. SECTION("Altc") {
  140. // altc:[2,2,2,2]
  141. JsonArray array = root["altc"];
  142. REQUIRE(array.isNull() == false);
  143. REQUIRE(4 == array.size());
  144. for (size_t i = 0; i < 4; i++) {
  145. REQUIRE(2 == array[i]);
  146. }
  147. }
  148. SECTION("Altd") {
  149. // altd:[2,2,2,2]
  150. JsonArray array = root["altd"];
  151. REQUIRE(array.isNull() == false);
  152. REQUIRE(4 == array.size());
  153. for (size_t i = 0; i < 4; i++) {
  154. REQUIRE(2 == array[i]);
  155. }
  156. }
  157. }