A C++ toolbox repo until the pair uTL/dTL arives
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

217 行
8.5 KiB

  1. /*!
  2. * \file main.cpp
  3. * \brief Test project main file
  4. *
  5. * \copyright Copyright (C) 2020-2021 Christos Choutouridis <christos@choutouridis.net>
  6. *
  7. * <dl class=\"section copyright\"><dt>License</dt><dd>
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in all
  16. * copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  24. * SOFTWARE.
  25. * </dd></dl>
  26. *
  27. */
  28. #include <gtest/gtest.h>
  29. #include <exception>
  30. //#include <drv/BG95_base.h>
  31. //#include <gtest/gtest.h>
  32. //#include <cont/equeue.h>
  33. ////#include <map>
  34. //
  35. ////#include <iostream>
  36. //#include <cstring>
  37. //#include <utility>
  38. //
  39. //#ifndef WIN_TRHEADS
  40. //#include <mutex>
  41. //#include <thread>
  42. //#else
  43. //#include <mingw.thread.h>
  44. //#include <mingw.mutex.h>
  45. //#endif
  46. //
  47. //using namespace tbx;
  48. //
  49. //using Q = equeue<char, 512, true>;
  50. //
  51. //// BG95 implementer mock
  52. //class BG95 : public BG95_base<BG95, Q, 256> {
  53. // using base_type = BG95_base<BG95, Q, 256>;
  54. //
  55. // public:
  56. // enum class event {
  57. // MQTT_DISCONNECT, MQTT_RXDATA
  58. // };
  59. // // simulated modem operation
  60. // private:
  61. // struct cmd_pair {
  62. // const char *cmd;
  63. // const char *resp;
  64. // };
  65. // struct event_pair {
  66. // event e;
  67. // const char* resp;
  68. // };
  69. //
  70. // std::array<cmd_pair, 19> cmd_map = {{
  71. // {"ERROR", "\r\nERROR\r\n"},
  72. // {"ATE0\r\n", "\r\nATE0\r\nOK\r\n"},
  73. // {"AT\r\n", "\r\nOK\r\n"},
  74. // {"AT+QCFG=\"nwscanseq\"\r\n", "\r\n+QCFG: \"nwscanseq\",020301\r\n"},
  75. // {"AT+QCFG=\"nwscanseq\",010302\r\n", "\r\nOK\r\n"},
  76. // {"AT+CREG?\r\n", "\r\n+CREG: 0,5\r\n\r\nOK\r\n"},
  77. // {"AT+CSQ\r\n", "\r\n+CSQ: 19,99\r\n\r\nOK\r\n"},
  78. // {"AT+QNWINFO\r\n", "\r\n+QNWINFO: \"EDGE\",\"20201\",\"GSM 1800\",865\r\n\r\nOK\r\n"},
  79. // // Files
  80. // {"AT+QFLST\r\n", "\r\n+QFLST: \"cacert.pem\",1220\r\n+QFLST: \"security/\",2\r\nOK\r\n"},
  81. // // MQTT config
  82. // {"AT+QSSLCFG=\"ignorelocaltime\",2,1\r\n", "\r\nOK\r\n"},
  83. // {"AT+QSSLCFG=\"seclevel\",2,1\r\n", "\r\nOK\r\n"},
  84. // {"AT+QSSLCFG=\"sslversion\",2,4\r\n", "\r\nOK\r\n"},
  85. // {"AT+QSSLCFG=\"ciphersuite\",2\r\n", "\r\n+QSSLCFG: \"ciphersuite\",2,0XFFFF\r\n\r\nOK\r\n"},
  86. // {"AT+QMTCFG=\"ssl\",0,1,2\r\n", "\r\nOK\r\n"},
  87. // {"AT+QMTCFG=\"keepalive\",0,3600\r\n", "\r\nOK\r\n"},
  88. // // MQTT
  89. // {"AT+QMTOPEN=0,\"server.com\",8883\r\n", "\r\nOK\r\n\r\n+QMTOPEN: 0,0\r\n"},
  90. // {"AT+QMTCONN=0,\"myID\",\"user\",\"pass\"\r\n", "\r\nOK\r\n\r\n+QMTCONN: 0,0,0\r\n"},
  91. // {"AT+QMTSUB=0,1,\"/path/topic1\",2\r\n", "\r\nOK\r\n\r\n+QMTSUB: 0,1,0,2\r\n"},
  92. // {"AT+QMTPUB=0,0,0,0,\"/path/topic2\",9\r\n", "\r\n> \r\nOK\r\n\r\n+QMTPUB: 0,0,0\r\n"},
  93. // }};
  94. // std::array<event_pair, 2> event_map {{
  95. // {event::MQTT_DISCONNECT, "\r\n+QMTSTAT: 0,1\r\n"},
  96. // {event::MQTT_RXDATA, "\r\n+QMTRECV: 0,1,\"/path/topic1\",\"BR: hello to all of my subscribers\""}
  97. // }};
  98. // const char* cmd_responce (const char* cmd) {
  99. // for (auto& it : cmd_map) {
  100. // if (!strcmp(it.cmd, cmd))
  101. // return it.resp;
  102. // }
  103. // return cmd_map[0].resp;
  104. // }
  105. // const char* event_responce (const event e) {
  106. // for (auto& it : event_map) {
  107. // if (e == it.e)
  108. // return it.resp;
  109. // }
  110. // return nullptr; // non reachable
  111. // }
  112. //
  113. // // data
  114. // Q rx_q{};
  115. // std::atomic<size_t> lines{};
  116. // public:
  117. // using range_t = typename Q::range_t;
  118. //
  119. // public:
  120. // // BG95_base driver requirements
  121. // BG95() :
  122. // rx_q(Q::data_match::MATCH_PUSH, base_type::delimiter, [&](){
  123. // lines.fetch_add(1, std::memory_order_acq_rel);
  124. // }), lines(0) { }
  125. //
  126. // size_t get(char* data, bool wait =false) {
  127. // do {
  128. // if (lines.load(std::memory_order_acquire)) {
  129. // size_t n =0;
  130. // do{
  131. // *data << rx_q;
  132. // ++n;
  133. // } while (*data++ != base_type::delimiter);
  134. // lines.fetch_sub(1, std::memory_order_acq_rel);
  135. // return n;
  136. // }
  137. // } while (wait);
  138. // return 0;
  139. // }
  140. // size_t put (const char* data, size_t n) {
  141. // const char* reply = cmd_responce (data);
  142. // while (*reply)
  143. // rx_q << *reply++;
  144. // return n;
  145. // }
  146. // const range_t contents() const {
  147. // return range_t {rx_q.begin(), rx_q.end()};
  148. // }
  149. // clock_t clock() { static clock_t t=0; return ++t; }
  150. //
  151. // // extra helper for testing purposes
  152. // void async (event e) {
  153. // const char* reply =event_responce (e);
  154. // while (*reply)
  155. // rx_q << *reply++;
  156. // }
  157. //};
  158. //
  159. //// Behavior flag
  160. //bool handler_flag = false;
  161. //void handler (const char* data, size_t n) {
  162. // (void)*data;
  163. // (void)n;
  164. //// std::cout << "* handler called\n";
  165. // handler_flag = true;
  166. //}
  167. //void clear_flag () {
  168. // handler_flag = false;
  169. //}
  170. //
  171. //int main(int argc, char **argv) try {
  172. // BG95 modem;
  173. //
  174. // const BG95::async_handlers<2> async = {{
  175. // {"+QMTOPEN:", BG95::match_t::STARTS_WITH, handler, BG95::action_t::NO, 0},
  176. // {"+QMT", BG95::match_t::STARTS_WITH, handler, BG95::action_t::NO, 0},
  177. // }};
  178. // const BG95::script_t<5, 2> script = {{
  179. // /* 0 */{BG95::control_t::NOP, {"", BG95::match_t::NO, nullptr, BG95::action_t::GOTO, 1}, 1000},
  180. // /* 1 */{BG95::control_t::SEND, {"ATE0\r\n", BG95::match_t::NO, nullptr, BG95::action_t::NEXT, 0}, 0},
  181. // /* 2 */{BG95::control_t::EXPECT, {{
  182. // {"OK\r\n", BG95::match_t::ENDS_WITH, nullptr, BG95::action_t::NEXT, 0},
  183. // {"ERROR", BG95::match_t::CONTAINS, nullptr, BG95::action_t::EXIT_ERROR, 0} }},
  184. // 1000
  185. // },
  186. // /* 3 */{BG95::control_t::SEND, {"AT+CSQ\r\n", BG95::match_t::NO, nullptr, BG95::action_t::NEXT, 0}, 0},
  187. // /* 4 */{BG95::control_t::EXPECT, {{
  188. // {"OK\r\n", BG95::match_t::ENDS_WITH, nullptr, BG95::action_t::EXIT_OK, 0},
  189. // {"ERROR", BG95::match_t::CONTAINS, nullptr, BG95::action_t::EXIT_ERROR, 0} }},
  190. // 1000
  191. // },
  192. // }};
  193. //
  194. // std::atomic<bool> lock(true);
  195. // std::thread th1 ([&](){
  196. // do
  197. // modem.inetd(async, false);
  198. // while (lock.load(std::memory_order_acquire));
  199. // });
  200. // EXPECT_EQ (modem.run(script), true);
  201. // lock.store(false, std::memory_order_acq_rel);
  202. // th1.join();
  203. //
  204. //}
  205. //catch (std::exception& e) {
  206. // std::cout << "Exception: " << e.what() << '\n';
  207. //}
  208. GTEST_API_ int main(int argc, char **argv) try {
  209. testing::InitGoogleTest(&argc, argv);
  210. return RUN_ALL_TESTS();
  211. }
  212. catch (std::exception& e) {
  213. std::cout << "Exception: " << e.what() << '\n';
  214. }