Debian Codegraph @

src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/micromock/inc/micromockenumtostring.h

raw
1 // Copyright (c) Microsoft. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
4 #ifndef MICROMOCKENUMTOSTRING_H
5 #define MICROMOCKENUMTOSTRING_H
6
7 #ifdef USE_TDD4CPP
8
9 #define MICROMOCK_ENUM_TO_STRING(EnumName, ...) \
10 namespace TDD \
11 { \
12 const wchar_t* EnumName##_Strings[] = { __VA_ARGS__ }; \
13 template <> std::string ToString<std::string, EnumName>(const EnumName& q) \
14 { \
15 if((size_t)q >= sizeof(EnumName##_Strings)/sizeof(EnumName##_Strings[0])) \
16 { \
17 return (L"out of range value for " #EnumName) \
18 } \
19 else \
20 { \
21 const wchar_t* w = EnumName##_Strings[q]; \
22 std::setlocale(LC_ALL, ""); \
23 std::wstring t(w); \
24 std::string s(t.length()+1, 0); \
25 std::locale loc(""); \
26 std::use_facet < std::ctype < wchar_t > >(loc).narrow(w, &w[t.length()], '\0', &s[0]); \
27 s.resize(t.length()); \
28 return s; \
29 } \
30 } \
31 };
32
33 #elif defined USE_CTEST
34 #define MICROMOCK_ENUM_TO_STRING(EnumName, ...) \
35 const wchar_t *EnumName##_Strings[]= \
36 { \
37 __VA_ARGS__ \
38 }; \
39 static void EnumName##_ToString(char* dest, size_t bufferSize, EnumName enumValue) \
40 { \
41 (void)snprintf(dest, bufferSize, "%S", EnumName##_Strings[enumValue]); \
42 } \
43 static bool EnumName##_Compare(EnumName left, EnumName right) \
44 { \
45 return left != right; \
46 }
47
48 #else
49
50 #define MICROMOCK_ENUM_TO_STRING(EnumName, ...) \
51 namespace Microsoft \
52 { \
53 namespace VisualStudio \
54 { \
55 namespace CppUnitTestFramework \
56 { \
57 static const wchar_t *EnumName##_Strings[]= \
58 { \
59 __VA_ARGS__ \
60 }; \
61 template <> std::wstring ToString < EnumName > (const EnumName & q) \
62 { \
63 if((size_t)q>=sizeof(EnumName##_Strings)/sizeof(EnumName##_Strings[0])) \
64 { \
65 return (L"out of range value for " L#EnumName); \
66 } \
67 else \
68 { \
69 return EnumName##_Strings[q]; \
70 } \
71 } \
72 } \
73 } \
74 };
75
76 #endif
77
78 #endif