File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include < cassert>
2+ #include < cstdint>
3+ #include < string>
4+
5+ using std::string;
6+ using std::uint8_t ;
7+
8+ extern " C" enum class AllocResult : uint8_t {
9+ OK ,
10+ NULL_DEFERENCE_ERR ,
11+ CONVERT_TO_STR_FAILED ,
12+ };
13+
14+ extern " C" AllocResult time_now (char **out);
15+ extern " C" void raw_free_c_str (char *str);
16+
17+ void null_deference_test () {
18+ using R = AllocResult;
19+
20+ auto result = time_now (nullptr );
21+ assert (result != R::CONVERT_TO_STR_FAILED );
22+ assert (result != R::OK );
23+ assert (result == R::NULL_DEFERENCE_ERR );
24+ }
25+
26+ void time_now_test () {
27+ using R = AllocResult;
28+
29+ char *out = nullptr ;
30+ auto result = time_now (&out);
31+ auto time_now_string = string (out);
32+ raw_free_c_str (out);
33+
34+ assert (result != R::CONVERT_TO_STR_FAILED );
35+ assert (result != R::NULL_DEFERENCE_ERR );
36+ assert (result == R::OK );
37+ assert (!time_now_string.empty ());
38+ }
39+
40+ int main () {
41+ null_deference_test ();
42+ time_now_test ();
43+ return 0 ;
44+ }
You can’t perform that action at this time.
0 commit comments