General Purpose library for Freestanding C++ and POSIX systems
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

224 行
5.4 KiB

  1. #include "test_scaffold.h"
  2. #include "gp/containers/array.hpp"
  3. #include "gp/system/logging_segment.hpp"
  4. #include <chrono>
  5. #include <cmath>
  6. #include <fstream>
  7. #include <iomanip>
  8. #include <iostream>
  9. struct logging_test : public test_scaffold {
  10. logging_test() {
  11. name = __FILE__ ":1";
  12. }
  13. virtual int run() {
  14. int res = 0;
  15. const gp::buffer<char> name{"FIRST TEST"};
  16. const gp::buffer<char> text{"FIRST TEST TEXT"};
  17. const gp::buffer<char> new_text{"NEW TEST TEXT"};
  18. static_logging_segment<4> logger;
  19. gp_config::assertion(logger.size() == 0, "new logger not empty");
  20. logger.push_segment(name, text);
  21. gp_config::assertion(logger.size() == 1, "should be 1 after insertion");
  22. logger.set_segment(name, new_text);
  23. gp_config::assertion(logger.size() == 1, "should still be one as key is identical");
  24. return res;
  25. }
  26. };
  27. append_test dummy_rduhk786f(new logging_test{});
  28. struct logging_test2 : public test_scaffold {
  29. logging_test2() {
  30. name = __FILE__ ":2";
  31. }
  32. virtual int run() {
  33. int res = 0;
  34. const gp::buffer<char> name[5]{{"TEST 1"},{"TEST 2"},{"TEST 3"},{"TEST 4"},{"TEST 5"}};
  35. const gp::buffer<char> texts[5] {{"NEW TEST TEXT 1"},{"NEW TEST TEXT 2"},{"NEW TEST TEXT 3"},{"NEW TEST TEXT 4"},{"NEW TEST TEXT 5"}};
  36. static_logging_segment<4> logger;
  37. gp_config::assertion(logger.size() == 0, "new logger not empty");
  38. for(auto i : {0,1,2,3,4}) {
  39. logger.push_segment(name[i], texts[i]);
  40. }
  41. gp_config::assertion(logger.size() <= 4, "Size should be capped at 4");
  42. gp_config::assertion(logger.size() == 4, "Size should be 4");
  43. return res;
  44. }
  45. };
  46. append_test dummy_sghgfg6f(new logging_test2{});
  47. struct logging_test3 : public test_scaffold {
  48. logging_test3() {
  49. name = __FILE__ ":3";
  50. }
  51. virtual int run() {
  52. int res = 0;
  53. const gp::buffer<char> name[5]{{"TEST 1"},{"TEST 2"},{"TEST 3"},{"TEST 4"},{"TEST 5"}};
  54. const gp::buffer<char> texts[5] {{"NEW TEST TEXT 1"},{"NEW TEST TEXT 2"},{"NEW TEST TEXT 3"},{"NEW TEST TEXT 4"},{"NEW TEST TEXT 5"}};
  55. static_logging_segment<4> logger;
  56. gp_config::assertion(logger.size() == 0, "new logger not empty");
  57. for(auto i : {0,1,2,3,4}) {
  58. logger.set_segment(name[i], texts[i]);
  59. log_segment("new element", name[i].begin().data);
  60. }
  61. log_segment("size", std::to_string(logger.size()).c_str());
  62. gp_config::assertion(logger.size() <= 4, "Size should be capped at 4");
  63. gp_config::assertion(logger.size() == 4, "Size should be 4");
  64. return res;
  65. }
  66. };
  67. append_test dummy_dgiudfg6f(new logging_test3{});
  68. struct logging_test4 : public test_scaffold {
  69. logging_test4() {
  70. name = __FILE__ ":4";
  71. }
  72. virtual int run() {
  73. int res = 0;
  74. const gp::buffer<char> name[5]{{"TEST 1"},{"TEST 2"},{"TEST 3"},{"TEST 4"},{"TEST 5"}};
  75. const gp::buffer<char> texts[5] {{"NEW TEST TEXT 1"},{"NEW TEST TEXT 2"},{"NEW TEST TEXT 3"},{"NEW TEST TEXT 4"},{"NEW TEST TEXT 5"}};
  76. static_logging_segment<4> logger;
  77. gp_config::assertion(logger.size() == 0, "new logger not empty");
  78. for(auto i : {0,1,2,3,4}) {
  79. logger.set_segment(name[i], texts[i]);
  80. }
  81. log_segment("size", std::to_string(logger.size()).c_str());
  82. gp_config::assertion(logger.size() <= 4, "Size should be capped at 4");
  83. gp_config::assertion(logger.size() == 4, "Size should be 4");
  84. for(auto i : {0, 1, 2, 3}) {
  85. auto v = logger.get_segment_by_idx(i);
  86. bool same = true;
  87. log_segment("found", std::string(v.name.begin().data, v.name.size()).c_str());
  88. for(size_t it = 0; it < name[0].size(); it++) {
  89. same &= name[0][it] == v.name[it];
  90. }
  91. gp_config::assertion(!same, "Should not contain oldest element");
  92. }
  93. return res;
  94. }
  95. };
  96. append_test dummy_aertm46f(new logging_test4{});
  97. struct logging_test5 : public test_scaffold {
  98. logging_test5() {
  99. name = __FILE__ ":5";
  100. }
  101. virtual int run() {
  102. int res = 0;
  103. const gp::buffer<char> name[5]{{"TEST 1"},{"TEST 2"},{"TEST 3"},{"TEST 4"},{"TEST 5"}};
  104. const gp::buffer<char> texts[5] {{"NEW TEST TEXT 1"},{"NEW TEST TEXT 2"},{"NEW TEST TEXT 3"},{"NEW TEST TEXT 4"},{"NEW TEST TEXT 5"}};
  105. const uint16_t prios[5] {1,1,0,1,1};
  106. static_logging_segment<4> logger;
  107. gp_config::assertion(logger.size() == 0, "new logger not empty");
  108. for(auto i : {0,1,2,3,4}) {
  109. logger.set_segment(name[i], texts[i], prios[i]);
  110. }
  111. log_segment("size", std::to_string(logger.size()).c_str());
  112. gp_config::assertion(logger.size() <= 4, "Size should be capped at 4");
  113. gp_config::assertion(logger.size() == 4, "Size should be 4");
  114. for(auto i : {0, 1, 2, 3}) {
  115. auto v = logger.get_segment_by_idx(i);
  116. log_segment("prio value", std::to_string(v.priority).c_str());
  117. gp_config::assertion(v.priority != 0, "Should not contain low prio element");
  118. }
  119. return res;
  120. }
  121. };
  122. append_test dummy_azefdhi6f(new logging_test5{});
  123. struct logging_test6 : public test_scaffold {
  124. logging_test6() {
  125. name = __FILE__ ":6";
  126. }
  127. virtual int run() {
  128. int res = 0;
  129. const gp::buffer<char> name{"FIRST TEST"};
  130. const gp::buffer<char> text{"FIRST TEST TEXT"};
  131. const gp::buffer<char> new_text{"NEW TEST TEXT"};
  132. static_logging_segment<4> logger;
  133. gp_config::assertion(logger.size() == 0, "new logger not empty");
  134. logger.push_segment(name, text);
  135. gp_config::assertion(logger.size() == 1, "should be 1 after insertion");
  136. logger.set_segment(name, new_text);
  137. gp_config::assertion(logger.size() == 1, "should still be one as key is identical");
  138. logger.clear();
  139. gp_config::assertion(logger.size() == 0, "should be zero after clear");
  140. return res;
  141. }
  142. };
  143. append_test dummy_ra45645sdf(new logging_test6{});