1 //******************************************************************
3 // Copyright 2014 Intel Corporation All Rights Reserved.
4 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
12 // Headers Required For the Tests
13 #include "OCPlatform.h"
15 #include "OCReflect.h"
20 using namespace OC::OCReflect;
22 void Test_OCFunction_0(int functionIndex);
23 void Test_OCFunction_1(int functionIndex);
24 void Test_OCFunction_2(int functionIndex);
25 void Test_OCFunction_3(int functionIndex);
26 void Test_OCFunction_4(int functionIndex);
27 void Test_OCFunction_5(int functionIndex);
28 void Test_OCFunction_6(int functionIndex);
29 void Test_OCFunction_7(int functionIndex);
30 void Test_OCFunction_8(int functionIndex);
31 void Test_OCFunction_9(int functionIndex);
32 void Test_OCFunction_10(int functionIndex);
33 void Test_OCFunction_11(int functionIndex);
34 void Test_OCFunction_12(int functionIndex);
36 FunctionStruct functionStruct[] = {
37 { &Test_OCFunction_0, "OCInProcServer", "DNRT" },
38 { &Test_OCFunction_1, "OCOutOfProcServer", "DNRT" },
39 { &Test_OCFunction_2, "OCInProcServer - registerResource", "DNRT" },
40 { &Test_OCFunction_3, "OCOutOfProcServer - registerResource", "DNRT" },
41 { &Test_OCFunction_4, "remote_resource", "DNRT" },
42 { &Test_OCFunction_5, "remoteResource - operator", "DNRT" },
43 { &Test_OCFunction_6, "method", "DNRT" },
44 { &Test_OCFunction_7, "method - operator", "DNRT" },
45 { &Test_OCFunction_8, "~OCInProcServer", "DNRT" },
46 { &Test_OCFunction_9, "~OCOutOfProcServer", "DNRT" },
47 { &Test_OCFunction_10, "~remote_resource", "DNRT" },
48 { &Test_OCFunction_11, "~OCResource", "DNRT" },
49 { &Test_OCFunction_12, "~method", "DNRT" },
52 InProcServerWrapper *pInProcServer = nullptr;
53 OutOfProcServerWrapper *pOutProcServer = nullptr;
54 remote_resource *pRemoteResource = nullptr;
55 OCResource *pResource = nullptr;
56 method *pMethod = nullptr;
60 int functionIndex = 0, functionNameSize = 0, functionNameLen = 0, functionCount = 0;
61 int resultSize = 0, resultLen = 0, lenOfResult = 0;
62 char rightSide[MaxResultSize], a;
65 // Get The Size Of Each Of The Structure Elements
66 functionCount = ElementCount(functionStruct);
79 Test_OCFunction_10(10);
80 Test_OCFunction_11(11);
81 Test_OCFunction_12(12);
83 for (functionIndex = 0; functionIndex < functionCount; functionIndex++)
85 functionNameLen = strlen((char*)&functionStruct[functionIndex].m_FunctionName);
86 if (functionNameLen > functionNameSize)
87 functionNameSize = functionNameLen;
89 resultLen = strlen((char*)&functionStruct[functionIndex].m_Result);
90 if (resultLen > resultSize)
91 resultSize = resultLen;
94 for (functionIndex = 0; functionIndex < functionCount; functionIndex++)
96 // Set The Width Of This Line
97 cout.width(ResultColumn);
99 // Print The Function Name
100 cout << left << functionStruct[functionIndex].m_FunctionName;
103 strcpy((char*)&rightSide, (char*)&functionStruct[functionIndex].m_Result);
104 lenOfResult = strlen((char*)&functionStruct[functionIndex].m_Result);
105 memset((char*)&rightSide[lenOfResult], ' ', MaxResultSize - lenOfResult);
106 rightSide[MaxResultSize - 1] = 0;
107 cout << right << rightSide << endl;
110 cin >> a; // Wait For Keyboard Input
114 void Test_OCFunction_0(int functionIndex)
121 cfg.serviceType = ServiceType::InProc;
122 cfg.mode = ModeType::Server;
123 cfg.ipAddress = "192.168.1.5";
126 pInProcServer = new InProcServerWrapper(cfg);
138 strcpy((char*)&functionStruct[functionIndex].m_Result, "Pass");
142 strcpy((char*)&functionStruct[functionIndex].m_Result, "Fail");
146 void Test_OCFunction_1(int functionIndex)
153 cfg.serviceType = ServiceType::InProc;
154 cfg.mode = ModeType::Server;
155 cfg.ipAddress = "192.168.1.5";
158 pOutProcServer = new OutOfProcServerWrapper(cfg);
170 strcpy((char*)&functionStruct[functionIndex].m_Result, "Pass");
174 strcpy((char*)&functionStruct[functionIndex].m_Result, "Fail");
178 void Test_OCFunction_2(int functionIndex)
181 string resName, resType;
182 named_property_binding_vector vc;
186 if (pInProcServer != nullptr)
188 resName = "ResourceName";
189 resType = "ResourceType";
190 pInProcServer->registerResource(resName, resType, vc);
202 strcpy((char*)&functionStruct[functionIndex].m_Result, "Pass");
206 strcpy((char*)&functionStruct[functionIndex].m_Result, "Fail");
210 void Test_OCFunction_3(int functionIndex)
213 string resName, resType;
214 named_property_binding_vector vc;
218 if (pOutProcServer != nullptr)
220 resName = "ResourceName";
221 resType = "ResourceType";
222 pOutProcServer->registerResource(resName, resType, vc);
234 strcpy((char*)&functionStruct[functionIndex].m_Result, "Pass");
238 strcpy((char*)&functionStruct[functionIndex].m_Result, "Fail");
242 void Test_OCFunction_4(int functionIndex)
244 bool bResult = false;
246 boost::property_tree::ptree tree;
251 loc = "Nowhere Special";
252 pResource = new OCResource(host, tree);
253 pRemoteResource = new remote_resource(*pResource, loc);
259 cout << "Ouch!" << endl;
265 strcpy((char*)&functionStruct[functionIndex].m_Result, "Pass");
269 strcpy((char*)&functionStruct[functionIndex].m_Result, "Fail");
273 void Test_OCFunction_5(int functionIndex)
275 bool bResult = false;
276 OC::OCReflect::entity localEntity;
284 //localEntity = pRemoteResource;//(str);
296 strcpy((char*)&functionStruct[functionIndex].m_Result, "Pass");
300 strcpy((char*)&functionStruct[functionIndex].m_Result, "Fail");
304 void Test_OCFunction_6(int functionIndex)
306 bool bResult = false;
311 if (pResource != nullptr)
314 pMethod = new method(*pResource, str);
326 strcpy((char*)&functionStruct[functionIndex].m_Result, "Pass");
330 strcpy((char*)&functionStruct[functionIndex].m_Result, "Fail");
334 void Test_OCFunction_7(int functionIndex)
336 bool bResult = false;
337 OC::OCReflect::tagged_property prop;
341 if (pMethod != nullptr)
343 //prop = pMethod(TS ...xs);
355 strcpy((char*)&functionStruct[functionIndex].m_Result, "Pass");
359 strcpy((char*)&functionStruct[functionIndex].m_Result, "Fail");
363 void Test_OCFunction_8(int functionIndex)
365 bool bResult = false;
369 if (pInProcServer != nullptr)
371 delete pInProcServer;
383 strcpy((char*)&functionStruct[functionIndex].m_Result, "Pass");
387 strcpy((char*)&functionStruct[functionIndex].m_Result, "Fail");
391 void Test_OCFunction_9(int functionIndex)
393 bool bResult = false;
397 if (pOutProcServer != nullptr)
399 delete pOutProcServer;
411 strcpy((char*)&functionStruct[functionIndex].m_Result, "Pass");
415 strcpy((char*)&functionStruct[functionIndex].m_Result, "Fail");
419 void Test_OCFunction_10(int functionIndex)
421 bool bResult = false;
425 if (pRemoteResource != nullptr)
427 delete pRemoteResource;
439 strcpy((char*)&functionStruct[functionIndex].m_Result, "Pass");
443 strcpy((char*)&functionStruct[functionIndex].m_Result, "Fail");
448 void Test_OCFunction_11(int functionIndex)
450 bool bResult = false;
454 if (pResource != nullptr)
468 strcpy((char*)&functionStruct[functionIndex].m_Result, "Pass");
472 strcpy((char*)&functionStruct[functionIndex].m_Result, "Fail");
476 void Test_OCFunction_12(int functionIndex)
478 bool bResult = false;
482 if (pMethod != nullptr)
496 strcpy((char*)&functionStruct[functionIndex].m_Result, "Pass");
500 strcpy((char*)&functionStruct[functionIndex].m_Result, "Fail");