C++ベースのLightweightなHTTPサーバー
| Revision | 9700784b96894a057792d266dcdb3af2a0ba103c (tree) |
|---|---|
| Time | 2012-12-07 23:18:16 |
| Author | Michio Hirai <smg_ykz@user...> |
| Commiter | Michio Hirai |
[Refactor] Clarify some other EXPECTATION in ContainerForeach unit tests.
[Function] New introduction ARRAY_LENGTH() macro
| @@ -0,0 +1,17 @@ | ||
| 1 | + | |
| 2 | +#ifndef INC_MT_ARRAY_LENGTH_H_ | |
| 3 | +#define INC_MT_ARRAY_LENGTH_H_ | |
| 4 | + | |
| 5 | +namespace mt { | |
| 6 | + | |
| 7 | +template <typename T, size_t N> | |
| 8 | +inline unsigned int getArrayLength(const T (&)[N]) | |
| 9 | +{ | |
| 10 | + return N; | |
| 11 | +} | |
| 12 | + | |
| 13 | +} // namespace mt | |
| 14 | + | |
| 15 | +#define ARRAY_LENGTH(x) mt::getArrayLength(x) | |
| 16 | + | |
| 17 | +#endif // INC_MT_ARRAY_LENGTH_H_ |
| @@ -3,6 +3,7 @@ | ||
| 3 | 3 | #include <string> |
| 4 | 4 | #include "gtest/gtest.h" |
| 5 | 5 | #include "mt_container_foreach.h" |
| 6 | +#include "mt_array_length.h" | |
| 6 | 7 | |
| 7 | 8 | TEST(ContainerForeachTest, std_vector_container_test) |
| 8 | 9 | { |
| @@ -113,35 +114,22 @@ TEST(ContainerForeachConstTest, fixed_array_test) | ||
| 113 | 114 | std::string fixed_array[10]; |
| 114 | 115 | |
| 115 | 116 | const char* string_array[] = { |
| 116 | - "hello", | |
| 117 | - "world", | |
| 118 | - "3", | |
| 119 | - "4", | |
| 120 | - "5", | |
| 121 | - "6", | |
| 122 | - "good", | |
| 123 | - "bye", | |
| 124 | - "cruel", | |
| 125 | - "world" | |
| 117 | + "hello", "world", "3", "4", "5", "6", | |
| 118 | + "good", "bye", "cruel", "world" | |
| 126 | 119 | }; |
| 127 | 120 | |
| 128 | - | |
| 129 | 121 | unsigned int count = 0; |
| 130 | 122 | CONTAINER_FOREACH(std::string& item, fixed_array) { |
| 131 | 123 | item = string_array[count]; |
| 132 | 124 | ++count; |
| 133 | 125 | } |
| 134 | - | |
| 126 | + EXPECT_EQ(ARRAY_LENGTH(fixed_array), count); | |
| 135 | 127 | |
| 136 | 128 | count = 0; |
| 137 | 129 | CONTAINER_FOREACH_CONST(const std::string& item, fixed_array) { |
| 138 | 130 | EXPECT_STREQ(item.c_str(), string_array[count]); |
| 139 | 131 | ++count; |
| 140 | 132 | } |
| 141 | - | |
| 142 | - | |
| 143 | - | |
| 133 | + EXPECT_EQ(ARRAY_LENGTH(fixed_array), count); | |
| 144 | 134 | } |
| 145 | 135 | |
| 146 | - | |
| 147 | - |