Debian Codegraph @

src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/testtools/micromock/inc/micromockcharstararenullterminatedstrings.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 MicroMockCharStarArenullTerminatedStrings_H
5 #define MicroMockCharStarArenullTerminatedStrings_H
6
7 #ifndef MICROMOCK_H
8 #error the file MicroMockCharStarArenullTerminatedStrings can only be #included after #include "micromock.h"
9 #endif
10
11 /*for strcpy()*/
12 #include <string.h>
13
14 /*for malloc()*/
15 #include <stdlib.h>
16
17 /*for everything else*/
18 #include "stdafx.h"
19
20 template<>
21 class CMockValue <char*> :
22 public CMockValueBase
23 {
24 protected:
25 char* m_Value;
26 char* m_OriginalValue;
27 public:
28 CMockValue(_In_ char* value)
29 {
30 if(value==NULL)
31 {
32 m_Value=NULL;
33 }
34 else
35 {
36 size_t s= strlen(value);
37 m_OriginalValue = value;
38 m_Value = (char*)malloc(s + 1);
39 strcpy(m_Value, value);
40 }
41 }
42
43 virtual ~CMockValue()
44 {
45 if(m_Value!=NULL)
46 {
47 free(m_Value);
48 m_Value = NULL;
49 }
50 }
51
52 virtual std::tstring ToString() const
53 {
54 std::tostringstream strStream;
55 if (NULL == m_Value)
56 {
57 strStream << _T("NULL");
58 }
59 else
60 {
61 strStream << m_Value;
62 }
63 return strStream.str();
64 }
65
66 virtual bool EqualTo(_In_ const CMockValueBase* right)
67 {
68 return (*this == *(reinterpret_cast<const CMockValue<char*>*>(right)));
69
70 }
71
72 void SetValue(_In_ char* value)
73 {
74 if(value == NULL)
75 {
76 if(m_Value !=NULL)
77 {
78 free(m_Value);
79 m_Value = NULL;
80 }
81 else
82 {
83
84 }
85 }
86 else
87 {
88 size_t s = strlen(value);
89 if(m_Value !=NULL)
90 {
91 free(m_Value);
92 m_Value=NULL;
93 }
94 m_Value = (char*)malloc(s+1);
95 m_OriginalValue = value;
96 strcpy(m_Value, value);
97 };
98 }
99
100 char* GetValue() const
101 {
102 return m_Value;
103 }
104 };
105
106 template<>
107 class CMockValue <const char*> :
108 public CMockValueBase
109 {
110 protected:
111 char* m_Value;
112 const char* m_OriginalValue;
113 public:
114 CMockValue(_In_ const char* value)
115 {
116 if(value==NULL)
117 {
118 m_Value=NULL;
119 }
120 else
121 {
122 size_t s= strlen(value);
123 m_Value = (char*)malloc(s+1);
124 m_OriginalValue = value;
125 strcpy(m_Value, value);
126 }
127 }
128
129 virtual ~CMockValue()
130 {
131 if(m_Value!=NULL)
132 {
133 free(m_Value);
134 m_Value = NULL;
135 }
136 }
137
138 virtual std::tstring ToString() const
139 {
140 std::tostringstream strStream;
141 if (NULL == m_Value)
142 {
143 strStream << _T("NULL");
144 }
145 else
146 {
147 strStream << m_Value;
148 }
149 return strStream.str();
150 }
151
152 virtual bool EqualTo(_In_ const CMockValueBase* right)
153 {
154 return (*this == *(reinterpret_cast<const CMockValue<const char*>*>(right)));
155 }
156
157 void SetValue(_In_ const char* value)
158 {
159 if(value == NULL)
160 {
161 if(m_Value !=NULL)
162 {
163 free(m_Value);
164 m_Value = NULL;
165 }
166 else
167 {
168
169 }
170 }
171 else
172 {
173 size_t s = strlen(value);
174 if(m_Value !=NULL)
175 {
176 free(m_Value);
177 m_Value=NULL;
178 }
179 m_Value = (char*)malloc(s+1);
180 m_OriginalValue = value;
181 strcpy(m_Value, value);
182 };
183 }
184
185 const char* GetValue() const
186 {
187 return m_Value;
188 }
189 };
190
191 bool operator==(_In_ const CMockValue<char*>& lhs, _In_ const CMockValue<char*>& rhs);
192 bool operator==(_In_ const CMockValue<const char*>& lhs, _In_ const CMockValue<const char*>& rhs);
193
194 #endif