root/lang/cplusplus/i3/src/mol/src/Test2.cpp @ 18001

Revision 18001, 9.8 kB (checked in by saturday06, 5 years ago)

_s系のテストを映した

Line 
1#include <mol/PrecompiledHeaders.h>
2#include <mol/MscCrt.h>
3#include <boost/test/unit_test.hpp>
4
5
6//void* test_singletonpoolissingleton_otherfile() {
7//    return (void*)&(boost::singleton_pool<int, 1234>::singleton::instance());
8//}
9
10
11#define len basic_strnlen
12#define cat_s basic_strcat_s
13#define cpy_s basic_strcpy_s
14
15BOOST_AUTO_TEST_CASE(len_sdofjikm) {
16    BOOST_CHECK(len("0", 1) == 1);
17    BOOST_CHECK(len("Xo", 1) == 1);
18    BOOST_CHECK(len("foo", 3) == 3);
19    BOOST_CHECK(len("0123456789", 8) == 8);
20
21    BOOST_CHECK(len("", 1) == 0);
22    BOOST_CHECK(len("X", 2) == 1);
23    BOOST_CHECK(len("foo", 4) == 3);
24    BOOST_CHECK(len("0123456789", 10));
25
26    int a0[] = {0};
27    int a1[] = {1,0};
28    int a2[] = {1,2,0};
29    int a5[] = {1,2,3,4,5,0};
30
31    BOOST_CHECK(len(a1, 1) == 1);
32    BOOST_CHECK(len(a2, 1) == 1);
33    BOOST_CHECK(len(a5, 2) == 2);
34
35    BOOST_CHECK(len(a0, 1) == 0);
36    BOOST_CHECK(len(a1, 2) == 1);
37    BOOST_CHECK(len(a2, 3) == 2);
38    BOOST_CHECK(len(a5, 6) == 5);
39}
40
41
42#define DEFINE_BUFFERS      \
43    char buf1[1] = {8};     \
44    int  ibuf1[1] = {9};    \
45    char buf2[2] = {0,4};   \
46    int  ibuf2[2] = {5,0};  \
47    char buf10[10] = {7,8,9,10,11,0,13,14,15,16};      \
48    int  ibuf10[10] = {17,18,19,20,0,22,23,24,25,26}; \
49    char nebuf1[1] = {1};     \
50    int  neibuf10[10] = {17,18,19,20,21,22,23,24,25,26}; \
51    char ebuf1[1] = {0};     \
52    int  eibuf1[1] = {0};    \
53    char ebuf2[2] = {3,0};   \
54    int  eibuf2[2] = {0,3};  \
55    char ebuf10[10] = {0,8,9,0,11,12,13,0,15,16};      \
56    int  eibuf10[10] = {9,0,19,20,21,0,23,24,25,26};
57
58BOOST_AUTO_TEST_CASE(cat_dofij) {
59    const char src1[1] = "";
60    const int isrc1[1] = {0};
61    const char src2[2] = "f";
62    const int isrc2[2] = {60, 0};
63    const char src10[10] = "abcdefghi";
64    const int isrc10[10] = {60, 61, 62, 63, 64, 65, 66, 67, 68, 0};
65    typedef std::basic_string<int> istring;
66    using std::string;
67    {
68        DEFINE_BUFFERS;
69        BOOST_CHECK(cat_s<char>(0, 5/*any*/, 0/*any*/)           == EINVAL);
70        BOOST_CHECK(cat_s<int>(0, 5/*any*/, 0/*any*/)            == EINVAL);
71        BOOST_CHECK(cat_s<char>(nebuf1, 5/*any*/, 0/*any*/)      == EINVAL);
72        BOOST_CHECK(cat_s<int>(neibuf10, 5/*any*/, 0/*any*/)     == EINVAL);
73        BOOST_CHECK(cat_s<char>(0, 0/*any*/, src1 /*any*/)       == EINVAL);
74        BOOST_CHECK(cat_s<int>(neibuf10, 1/*any*/, isrc1/*any*/) == EINVAL);
75
76        BOOST_CHECK(cat_s<char>(ebuf1/*any*/,  5/*any*/,  0)  == EINVAL);
77        BOOST_CHECK(cat_s<int>(eibuf2/*any*/,  5/*any*/,  0)  == EINVAL);
78        BOOST_CHECK(cat_s<char>(ebuf10/*any*/, 0/*any*/,  0)  == EINVAL);
79        BOOST_CHECK(cat_s<int>(eibuf1/*any*/,  0/*any*/,  0)  == EINVAL);
80    }
81
82    {
83        DEFINE_BUFFERS;
84        BOOST_CHECK(cat_s<char>(ebuf1, 0, src1)   == ERANGE);
85        BOOST_CHECK(cat_s<int>(eibuf1, 0, isrc1)  == ERANGE);
86        BOOST_CHECK(cat_s<char>(ebuf1, 1, src10)  == ERANGE);
87        BOOST_CHECK(cat_s<int>(eibuf1, 1, isrc10) == ERANGE);
88        BOOST_CHECK(cat_s<char>(buf2, 2, src10)   == ERANGE);
89        BOOST_CHECK(cat_s<int>(eibuf2, 2, isrc10) == ERANGE);
90    }
91    {
92        char dst[] = {0,1,2,3,4,5}; const char src[] = {10,10,0};
93        string result = string(dst)+src;BOOST_CHECK(cat_s<char>(dst, _countof(dst), src) == 0);BOOST_CHECK(string(dst) == result); }
94    {
95        char dst[] = {1,1,0,3,4,5}; const char src[] = {10,10,0};
96        string result = string(dst)+src;BOOST_CHECK(cat_s<char>(dst, _countof(dst), src) == 0);BOOST_CHECK(string(dst) == result); }
97    {
98        char dst[] = {0,1,2,0,4,5}; const char src[] = {10,0};
99        string result = string(dst)+src;BOOST_CHECK(cat_s<char>(dst, _countof(dst), src) == 0);BOOST_CHECK(string(dst) == result); }
100    {
101        char dst[] = {1,1,2,3,4,0}; const char src[] = {0};
102        string result = string(dst)+src;BOOST_CHECK(cat_s<char>(dst, _countof(dst), src) == 0);BOOST_CHECK(string(dst) == result); }
103    {
104        char dst[] = {0,1,2,3,0,5}; const char src[] = {10, 0};
105        string result = string(dst)+src;BOOST_CHECK(cat_s<char>(dst, _countof(dst), src) == 0);BOOST_CHECK(string(dst) == result); }
106    {
107        char dst[] = {0}; const char src[] = {0};
108        string result = string(dst)+src;BOOST_CHECK(cat_s<char>(dst, _countof(dst), src) == 0);BOOST_CHECK(string(dst) == result); }
109    {
110        char dst[] = {1,0,0}; const char src[] = {10,0};
111        string result = string(dst)+src;BOOST_CHECK(cat_s<char>(dst, _countof(dst), src) == 0);BOOST_CHECK(string(dst) == result); }
112    {
113        char dst[] = {0,0,0,0,0}; const char src[] = {10,10,15,15,0};
114        string result = string(dst)+src;BOOST_CHECK(cat_s<char>(dst, _countof(dst), src) == 0);BOOST_CHECK(string(dst) == result); }
115    {
116        char dst[] = {0,1,2,3,4,5}; const char src[] = {10,10,0};
117        string result = string(dst)+src;BOOST_CHECK(cat_s<char>(dst, _countof(dst), src) == 0);BOOST_CHECK(string(dst) == result); }
118
119
120
121
122
123    {
124        double dst[] = {0,1,2,3,4,5}; const double src[] = {10,10,0};
125        std::basic_string<double> result = std::basic_string<double>(dst)+src;BOOST_CHECK(cat_s<double>(dst, _countof(dst), src) == 0);BOOST_CHECK(std::basic_string<double>(dst) == result); }
126    {
127        double dst[] = {1,1,0,3,4,5}; const double src[] = {10,10,0};
128        std::basic_string<double> result = std::basic_string<double>(dst)+src;BOOST_CHECK(cat_s<double>(dst, _countof(dst), src) == 0);BOOST_CHECK(std::basic_string<double>(dst) == result); }
129    {
130        double dst[] = {0,1,2,0,4,5}; const double src[] = {10,0};
131        std::basic_string<double> result = std::basic_string<double>(dst)+src;BOOST_CHECK(cat_s<double>(dst, _countof(dst), src) == 0);BOOST_CHECK(std::basic_string<double>(dst) == result); }
132    {
133        double dst[] = {1,1,2,3,4,0}; const double src[] = {0};
134        std::basic_string<double> result = std::basic_string<double>(dst)+src;BOOST_CHECK(cat_s<double>(dst, _countof(dst), src) == 0);BOOST_CHECK(std::basic_string<double>(dst) == result); }
135    {
136        double dst[] = {0,1,2,3,0,5}; const double src[] = {10, 0};
137        std::basic_string<double> result = std::basic_string<double>(dst)+src;BOOST_CHECK(cat_s<double>(dst, _countof(dst), src) == 0);BOOST_CHECK(std::basic_string<double>(dst) == result); }
138    {
139        double dst[] = {0}; const double src[] = {0};
140        std::basic_string<double> result = std::basic_string<double>(dst)+src;BOOST_CHECK(cat_s<double>(dst, _countof(dst), src) == 0);BOOST_CHECK(std::basic_string<double>(dst) == result); }
141    {
142        double dst[] = {1,0,0}; const double src[] = {10,0};
143        std::basic_string<double> result = std::basic_string<double>(dst)+src;BOOST_CHECK(cat_s<double>(dst, _countof(dst), src) == 0);BOOST_CHECK(std::basic_string<double>(dst) == result); }
144    {
145        double dst[] = {0,0,0,0,0}; const double src[] = {10,10,15,15,0};
146        std::basic_string<double> result = std::basic_string<double>(dst)+src;BOOST_CHECK(cat_s<double>(dst, _countof(dst), src) == 0);BOOST_CHECK(std::basic_string<double>(dst) == result); }
147    {
148        double dst[] = {0,1,2,3,4,5}; const double src[] = {10,10,0};
149        std::basic_string<double> result = std::basic_string<double>(dst)+src;BOOST_CHECK(cat_s<double>(dst, _countof(dst), src) == 0);BOOST_CHECK(std::basic_string<double>(dst) == result); }
150
151}
152
153BOOST_AUTO_TEST_CASE(cpy_saaaa) {
154    const char src1[1] = "";
155    const int isrc1[1] = {0};
156    const char src2[2] = "f";
157    const int isrc2[2] = {60, 0};
158    const char src10[10] = "abcdefghi";
159    const int isrc10[10] = {60, 61, 62, 63, 64, 65, 66, 67, 68, 0};
160    typedef std::basic_string<int> istring;
161    using std::string;
162
163    {
164        DEFINE_BUFFERS;
165        BOOST_CHECK(cpy_s<char>(0, 5/*any*/, 0/*any*/)      == EINVAL);
166        BOOST_CHECK(cpy_s<int>(0, 5/*any*/, 0/*any*/)       == EINVAL);
167        BOOST_CHECK(cpy_s<char>(0, 0/*any*/, src1 /*any*/)  == EINVAL);
168        BOOST_CHECK(cpy_s<int>(0, 0/*any*/, isrc1/*any*/)   == EINVAL);
169        BOOST_CHECK(cpy_s<char>(buf1/*any*/, 5/*any*/,  0)  == EINVAL);
170        BOOST_CHECK(cpy_s<int>(ibuf2/*any*/, 5/*any*/,  0)  == EINVAL);
171        BOOST_CHECK(cpy_s<char>(buf10/*any*/, 0/*any*/, 0)  == EINVAL);
172        BOOST_CHECK(cpy_s<int>(ibuf10/*any*/, 0/*any*/, 0)  == EINVAL);
173    }
174    {
175        DEFINE_BUFFERS;
176
177        BOOST_CHECK(cpy_s<char>(buf1, 0, src1)   == ERANGE);
178        BOOST_CHECK(cpy_s<int>(ibuf1, 0, isrc1)  == ERANGE);
179        BOOST_CHECK(cpy_s<char>(buf1, 1, src10)  == ERANGE);
180        BOOST_CHECK(cpy_s<int>(ibuf1, 1, isrc10) == ERANGE);
181        BOOST_CHECK(cpy_s<char>(buf2, 2, src10)  == ERANGE);
182        BOOST_CHECK(cpy_s<int>(ibuf2, 2, isrc10) == ERANGE);
183    }
184    {
185        DEFINE_BUFFERS;
186
187        BOOST_CHECK(cpy_s<char>(buf2, 2, src2) == 0);
188        BOOST_CHECK(string(buf2) == string(src2));
189        BOOST_CHECK(cpy_s<int>(ibuf2, 2, isrc2) == 0);
190        BOOST_CHECK(istring(ibuf2) == istring(isrc2));
191
192        BOOST_CHECK(cpy_s<char>(buf2, 2, src1) == 0);
193        BOOST_CHECK(string(buf2) == string(src1));
194        BOOST_CHECK(cpy_s<int>(ibuf2, 2, isrc1) == 0);
195        BOOST_CHECK(istring(ibuf2) == istring(isrc1));
196
197        BOOST_CHECK(cpy_s<char>(buf1, 1, src1) == 0);
198        BOOST_CHECK(string(buf1) == string(src1));
199        BOOST_CHECK(cpy_s<int>(ibuf1, 1, isrc1) == 0);
200        BOOST_CHECK(istring(ibuf1) == istring(isrc1));
201
202        BOOST_CHECK(cpy_s<char>(buf10, 10, src10) == 0);
203        BOOST_CHECK(string(buf10) == string(src10));
204        BOOST_CHECK(cpy_s<int>(ibuf10, 10, isrc10) == 0);
205        BOOST_CHECK(istring(ibuf10) == istring(isrc10));
206
207        BOOST_CHECK(cpy_s<char>(buf10, 10, src2) == 0);
208        BOOST_CHECK(string(buf10) == string(src2));
209        BOOST_CHECK(cpy_s<int>(ibuf10, 10, isrc2) == 0);
210        BOOST_CHECK(istring(ibuf10) == istring(isrc2));
211    }
212}
Note: See TracBrowser for help on using the browser.