/* **============================================================================== ** ** Open Management Infrastructure (OMI) ** ** Copyright (c) Microsoft Corporation ** ** Licensed under the Apache License, Version 2.0 (the "License"); you may not ** use this file except in compliance with the License. You may obtain a copy ** of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, ** MERCHANTABLITY OR NON-INFRINGEMENT. ** ** See the Apache 2 License for the specific language governing permissions ** and limitations under the License. ** **============================================================================== */ #include #include #include #include #include #include #include #include #include using namespace std; /* Local data */ static Sock s = INVALID_SOCK; static const char* s_currentNamespace = ""; static bool s_DisconnectAfterEachTest = false; static void setUp() { if (INVALID_SOCK == s) { s = SockConnectLocal(ut::getUnittestPortNumberWSMANHTTP()); } } static void cleanup() { if (s_DisconnectAfterEachTest) { if (INVALID_SOCK != s) Sock_Close(s); s = INVALID_SOCK; } } static string _CreateRequestXML( const char* cn, const char* ns, const char* enumerationMode = 0, const char* maxEnvelopeSize = 0, bool specifyNamespace = true) { string res = "" "" "http://linux-22kv:22000/wsman" "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/"; res += cn; res += "" "" "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous" "" "http://schemas.xmlsoap.org/ws/2004/09/enumeration/Enumerate" ""; if (maxEnvelopeSize) { res += maxEnvelopeSize; } else { res += "10240"; } res += "" "uuid:FEF3DF41-FFEC-4ABE-ADFC-A8305DAB71C9" ""; if (specifyNamespace) { res += ""; res += s_currentNamespace; res += ns; res += ""; } else { res += "value"; } res += "" "PT60.000S" "" "" "" "" "10"; if (enumerationMode) res += enumerationMode; res += "" ; return res; } static string _CreateInvokeRequestXML( const char* cn, const char* ns, const char* method, const char* params, const char* keys, bool specifyNamespace = true) { string res = "" "http://localhost:7778/wsman" "http://schemas.microsoft.com/wbem/wscim/1/cim-schema/2/"; res += cn; res += "" "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous" "http://schemas.microsoft.com/wbem/wscim/1/cim-schema/2/"; res += cn; res += "/"; res += method; res += "32768" "uuid:E8928068-D73B-4206-9E95-894088B96288" ""; if (specifyNamespace) { res += ""; res += s_currentNamespace; res += ns; res += ""; } else { res += "value"; } if (keys) res += keys; res += "PT60.000S" ""; res += params; res += ""; return res; } static string _CreateGetRequestXML( const char* cn, const char* ns, const char* keys, bool specifyNamespace = true) { string res = "" "http://localhost:7778/wsman" "" "http://schemas.microsoft.com/wbem/wscim/1/cim-schema/2/"; res += cn; res += "" "" "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous" "http://schemas.xmlsoap.org/ws/2004/09/transfer/Get" "" "32768" "uuid:E8928068-D73B-4206-9E95-894088B96288" "" ""; if (specifyNamespace) { res += ""; res += s_currentNamespace; res += ns; res += ""; } else { res += "value"; } if (keys) res += keys; res += "PT60.000S" ""; return res; } static string _CreateDeleteRequestXML( const char* cn, const char* ns, const char* keys, bool specifyNamespace = true) { string res = "" "http://localhost:7778/wsman" "" "http://schemas.microsoft.com/wbem/wscim/1/cim-schema/2/"; res += cn; res += "" "" "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous" "http://schemas.xmlsoap.org/ws/2004/09/transfer/Delete" "" "32768" "uuid:E8928068-D73B-4206-9E95-894088B96288" "" ""; if (specifyNamespace) { res += ""; res += s_currentNamespace; res += ns; res += ""; } else { res += "value"; } if (keys) res += keys; res += "PT60.000S" ""; return res; } static string _CreateCreateRequestXML( const char* cn, const char* ns, const char* props, bool specifyNamespace = true) { string res = "" "http://localhost:7778/wsman" "" "http://schemas.microsoft.com/wbem/wscim/1/cim-schema/2/"; res += cn; res += "" "" "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous" "http://schemas.xmlsoap.org/ws/2004/09/transfer/Create" "" "32768" "uuid:E8928068-D73B-4206-9E95-894088B96288" "" ""; if (specifyNamespace) { res += ""; res += s_currentNamespace; res += ns; res += ""; } else { res += "value"; } res += "PT60.000S"; res += props; res += ""; return res; } static string _CreateModifyRequestXML( const char* cn, const char* ns, const char* keys, const char* props, bool specifyNamespace = true) { string res = "" "http://localhost:7778/wsman" "" "http://schemas.microsoft.com/wbem/wscim/1/cim-schema/2/"; res += cn; res += "" "" "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous" "http://schemas.xmlsoap.org/ws/2004/09/transfer/Put" "" "32768" "uuid:E8928068-D73B-4206-9E95-894088B96288" "" ""; if (specifyNamespace) { res += ""; res += s_currentNamespace; res += ns; res += ""; } else { res += "value"; } if (keys) res += keys; res += "PT60.000S"; res += props; res += ""; return res; } static void TestWSMANemptyRequest() { string r_b, r_h; SockSendRecvHTTP(s, false, "", r_h, r_b ); // send invalid xml; expecting http 500 back UT_ASSERT(r_h.find("500") != string::npos); } static void TestWSMANInvalidXML() { string r_b, r_h; SockSendRecvHTTP(s, false, "invalid xml", r_h, r_b ); // send invalid xml; expecting http 500 back UT_ASSERT(r_h.find("500") != string::npos); } static void TestWSMAN_NotSupportedEncoding() { string r_b, r_h; // use utf16 encoding header SockSendRecvHTTP(s, true, _CreateRequestXML("X_number", "test/cpp").c_str(), r_h, r_b ); // send not-supported encoding; expecting http 500 back //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("500") != string::npos); } static void TestWSMAN_Fault_invalidNamespace() { string r_b, r_h; SockSendRecvHTTP(s, false, _CreateRequestXML("X_number", "invlaid/namespace").c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; // send invalid request; expecting http 500 back UT_ASSERT(r_h.find("500") != string::npos); UT_ASSERT(!r_b.empty()); UT_ASSERT(r_b.find("wsa:DestinationUnreachable") != string::npos); UT_ASSERT(r_b.find("CIM ERROR:INVALID_NAMESPACE") != string::npos); } static void TestWSMAN_Fault_instanceBiggerThaEnvelope() { string r_b, r_h; SockSendRecvHTTP(s, false, _CreateRequestXML("X_SingletonWithAllTypes", "test/cpp", 0, "8200").c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; // send envelope size is not enough to hold one instance; expecting http 500 back UT_ASSERT(r_h.find("500") != string::npos); UT_ASSERT(!r_b.empty()); UT_ASSERT(r_b.find("wsman:EncodingLimit") != string::npos); UT_ASSERT(r_b.find("insufficient envelope size") != string::npos); } static void TestWSMAN_Fault_invalidClass() { string r_b, r_h; SockSendRecvHTTP(s, false, _CreateRequestXML("InvalidClassname", "test/cpp").c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; // send invalid request; expecting http 500 back UT_ASSERT(r_h.find("500") != string::npos); UT_ASSERT(!r_b.empty()); UT_ASSERT(r_b.find("wsa:DestinationUnreachable") != string::npos); UT_ASSERT(r_b.find("CIM ERROR:INVALID_CLASS") != string::npos); } static void TestWSMAN_Enumerate_XProfile() { string r_b, r_h; SockSendRecvHTTP(s, false, _CreateRequestXML("X_Profile", "interop").c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); UT_ASSERT(r_b.find("World") != string::npos); UT_ASSERT(r_b.find("Huge Numbers") != string::npos); } static void TestWSMAN_Enumerate_XProfile_EPR_Only() { string r_b, r_h; SockSendRecvHTTP(s, false, _CreateRequestXML("X_Profile", "interop", "EnumerateEPR").c_str(), r_h, r_b ); // cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); /* expect EPR back */ UT_ASSERT(r_b.find("") != string::npos); UT_ASSERT(r_b.find("Name=\"InstanceID\">world<") != string::npos); UT_ASSERT(r_b.find("Name=\"InstanceID\">number<") != string::npos); /* regular properties shuld not be specified */ UT_ASSERT(r_b.find("World") == string::npos); UT_ASSERT(r_b.find("Huge Numbers") == string::npos); } static void TestWSMAN_Enumerate_XProfile_EPRAndObject() { string r_b, r_h; SockSendRecvHTTP(s, false, _CreateRequestXML("X_Profile", "interop", "EnumerateObjectAndEPR").c_str(), r_h, r_b ); // cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); /* expect EPR back */ UT_ASSERT(r_b.find("") != string::npos); UT_ASSERT(r_b.find("Name=\"InstanceID\">world<") != string::npos); UT_ASSERT(r_b.find("Name=\"InstanceID\">number<") != string::npos); /* and regular properties */ UT_ASSERT(r_b.find("World") != string::npos); UT_ASSERT(r_b.find("Huge Numbers") != string::npos); } static void TestWSMAN_Enumerate_X_SingletonWithAllTypes() { string r_b, r_h; SockSendRecvHTTP(s, false, _CreateRequestXML("X_SingletonWithAllTypes", "test/cpp", 0, "64000").c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data // (see X_SingletonWithAllTypes_Class_Provider.cpp to see how it was created) UT_ASSERT(r_b.find("id>1<") != string::npos); UT_ASSERT(r_b.find("b>TRUE<") != string::npos); UT_ASSERT(r_b.find("u8>172<") != string::npos); UT_ASSERT(r_b.find("u16>1745<") != string::npos); // inst.c16_value(1044); // in utf8 it's -48, -108 or 0xd0, 0x94 #if 0 UT_ASSERT(r_b.find("c16>\xd0\x94<") != string::npos); #else UT_ASSERT(r_b.find("c16>1044<") != string::npos); #endif UT_ASSERT(r_b.find("s8>-123<") != string::npos); UT_ASSERT(r_b.find("u16>1745<") != string::npos); UT_ASSERT(r_b.find("s16>-1746<") != string::npos); UT_ASSERT(r_b.find("u32>17567<") != string::npos); UT_ASSERT(r_b.find("s32>-17568<") != string::npos); UT_ASSERT(r_b.find("u64>18446744073709551613<") != string::npos); UT_ASSERT(r_b.find("s64>-9223372036854775805<") != string::npos); UT_ASSERT(r_b.find("s>string value<") != string::npos); /* due to truncation feature of float numbers, skip comparison of last digit */ UT_ASSERT(r_b.find("r32>32.3") != string::npos); UT_ASSERT(r_b.find("r64>64.646") != string::npos); UT_ASSERT(r_b.find("dt>2010-07-14T11:35:11.900675-00:07<") != string::npos); // person UT_ASSERT(r_b.find("person>") != string::npos); UT_ASSERT(r_b.find("MSFT_Person>") != string::npos); UT_ASSERT(r_b.find("Last>Smith<") != string::npos); UT_ASSERT(r_b.find("First>John<") != string::npos); UT_ASSERT(r_b.find("Key>7<") != string::npos); // object UT_ASSERT(r_b.find("objectSingle>") != string::npos); UT_ASSERT(r_b.find("X_TestObject>") != string::npos); UT_ASSERT(r_b.find("id>9000<") != string::npos); //UT_ASSERT(r_b.find("operation>?<") != string::npos); UT_ASSERT(r_b.find("right_operand xsi:nil=\"true\"/>") != string::npos); // test array values UT_ASSERT(r_b.find("bA>TRUE<") != string::npos); UT_ASSERT(r_b.find("bA>FALSE<") != string::npos); UT_ASSERT(r_b.find("u8A>0<") != string::npos); UT_ASSERT(r_b.find("u8A>255<") != string::npos); UT_ASSERT(r_b.find("u8A>128<") != string::npos); UT_ASSERT(r_b.find("s8A>0<") != string::npos); UT_ASSERT(r_b.find("s8A>127<") != string::npos); UT_ASSERT(r_b.find("s8A>-128<") != string::npos); UT_ASSERT(r_b.find("u16A>0<") != string::npos); UT_ASSERT(r_b.find("u16A>64000<") != string::npos); UT_ASSERT(r_b.find("s16A>0<") != string::npos); UT_ASSERT(r_b.find("s16A>-1216<") != string::npos); UT_ASSERT(r_b.find("s16A>258<") != string::npos); } static void TestWSMAN_Enumerate_X_HugeNumberConformsToProfile() { // Enumerate Assoc class and verify references are returned properly string r_b, r_h; SockSendRecvHTTP(s, false, _CreateRequestXML("X_HugeNumberConformsToProfile", "test/cpp").c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data UT_ASSERT(r_b.find(":Profile>") != string::npos); UT_ASSERT(r_b.find("Name=\"InstanceID\">number<") != string::npos); UT_ASSERT(r_b.find("1000000") != string::npos); } static void TestWSMAN_Enumerate_MissingNamespace() { string r_b, r_h; /* namespace param is missing - expecting error back */ SockSendRecvHTTP(s, false, _CreateRequestXML("X_Profile", "interop", 0, 0, false).c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("500") != string::npos); UT_ASSERT(r_b.find(">wsman:InternalError<") != string::npos); UT_ASSERT(r_b.find(">mandatory parameters") != string::npos); } static void TestWSMAN_Enumerate_X_HugeNumber_Deep() { // Enumerate X_HugeNumber - expecting back 3 instances string r_b, r_h; SockSendRecvHTTP(s, false, _CreateRequestXML("X_HugeNumber", "test/cpp", "IncludeSubClassProperties" ).c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data: expecting three items and property 'Property0' // all should present UT_ASSERT(r_b.find("Number>1000000<") != string::npos); UT_ASSERT(r_b.find("Number>1000000000<") != string::npos); UT_ASSERT(r_b.find("Number>1000001<") != string::npos); UT_ASSERT(r_b.find("Property0>9<") != string::npos); UT_ASSERT(r_b.find("ExcludeSubClassProperties" ).c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data: expecting three items and property 'Property0' // 3 instances are expected, but no sub-class properties/sub-class name UT_ASSERT(r_b.find("Number>1000000<") != string::npos); UT_ASSERT(r_b.find("Number>1000000000<") != string::npos); UT_ASSERT(r_b.find("Number>1000001<") != string::npos); UT_ASSERT(r_b.find("Property0>9<") == string::npos); UT_ASSERT(r_b.find("None" ).c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data: expecting three items and property 'Property0' // only 2 instances are expected - exact class match UT_ASSERT(r_b.find("Number>1000000<") != string::npos); UT_ASSERT(r_b.find("Number>1000000000<") != string::npos); UT_ASSERT(r_b.find("Number>1000001<") == string::npos); UT_ASSERT(r_b.find("Property0>9<") == string::npos); UT_ASSERT(r_b.find("77", "").c_str(), r_h, r_b ); // cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data UT_ASSERT(r_b.find("MIReturn>seventy seven<") != string::npos); } static void TestWSMAN_Invoke_MissingNamespace() { string r_b, r_h; SockSendRecvHTTP(s, false, _CreateInvokeRequestXML("X_Smallnumber", "test/cpp", "spellNumber", "77", "", false).c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("500") != string::npos); UT_ASSERT(!r_b.empty()); // check data UT_ASSERT(r_b.find(">wsman:InternalError<") != string::npos); UT_ASSERT(r_b.find("CIM ERROR:INVALID_PARAMETER") != string::npos); } static void TestWSMAN_Invoke_SmallNumber_SpellNumber_OOP() { string r_b, r_h; SockSendRecvHTTP(s, false, _CreateInvokeRequestXML("X_Smallnumber", "oop/requestor/test/cpp", "spellNumber", "77", "").c_str(), r_h, r_b ); // cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data UT_ASSERT(r_b.find("MIReturn>seventy seven<") != string::npos); } static void TestWSMAN_Invoke_TestEmbeddedObjectReturnKey20100609() { string r_b, r_h; SockSendRecvHTTP(s, false, _CreateInvokeRequestXML("TestEmbeddedOperations", "test/cpp", "TestEmbeddedObjectReturnKey20100609", "", "1").c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; if (r_h.find("200") == string::npos) cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; // send invalid request; expecting http 500 back UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data UT_ASSERT(r_b.find("ObjectID>20100609<") != string::npos); UT_ASSERT(r_b.find("X_TestEmbeddedObjectNotReferenced") != string::npos); } static void TestWSMAN_Invoke_TestEmbeddedObjectReturnKey20100609_OOP() { string r_b, r_h; SockSendRecvHTTP(s, false, _CreateInvokeRequestXML("TestEmbeddedOperations", "oop/requestor/test/cpp", "TestEmbeddedObjectReturnKey20100609", "", "1").c_str(), r_h, r_b ); // cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; // send invalid request; expecting http 500 back UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data UT_ASSERT(r_b.find("ObjectID>20100609<") != string::npos); UT_ASSERT(r_b.find("X_TestEmbeddedObjectNotReferenced") != string::npos); } static void TestWSMAN_Invoke_TestEmbedded() { const char* c_embeddedInstance = "\ \ 101\ \ "; string r_b, r_h; SockSendRecvHTTP(s, false, _CreateInvokeRequestXML("TestEmbeddedOperations", "test/cpp", "TestEmbedded", c_embeddedInstance, "1").c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data UT_ASSERT(r_b.find("Key>101<") != string::npos); UT_ASSERT(r_b.find("Species>test<") != string::npos); UT_ASSERT(r_b.find("MSFT_Animal") != string::npos); } static void TestWSMAN_Invoke_TestEmbeddedWithArray() { const char* c_embeddedInstance = "\ \ \ 101\ \ \ \ \ 102\ \ \ \ \ 103\ \ \ "; string r_b, r_h; SockSendRecvHTTP(s, false, _CreateInvokeRequestXML("TestEmbeddedOperations", "test/cpp", "TestEmbedded", c_embeddedInstance, "1").c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data UT_ASSERT(r_b.find("Key>101<") != string::npos); UT_ASSERT(r_b.find("Key>102<") != string::npos); UT_ASSERT(r_b.find("Key>103<") != string::npos); UT_ASSERT(r_b.find("Species>test<") != string::npos); UT_ASSERT(r_b.find("MSFT_Animal") != string::npos); } static void TestWSMAN_Invoke_TestEmbeddedWithMultipleArrays() { const char* c_embeddedInstance = "\ \ \ 101\ \ \ \ \ 102\ \ \ \ \ 103\ \ \ \ \ \ 9000109\ \ \ \ \ some string\ 9000209\ \ \ \ \ 9000309\ +\ 1719\ \ \ "; string r_b, r_h; SockSendRecvHTTP(s, false, _CreateInvokeRequestXML("TestEmbeddedOperations", "test/cpp", "TestEmbedded", c_embeddedInstance, "1").c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data UT_ASSERT(r_b.find("Key>101<") != string::npos); UT_ASSERT(r_b.find("Key>102<") != string::npos); UT_ASSERT(r_b.find("Key>103<") != string::npos); UT_ASSERT(r_b.find("Species>test<") != string::npos); UT_ASSERT(r_b.find("MSFT_Animal") != string::npos); UT_ASSERT(r_b.find("MIReturn") != string::npos); UT_ASSERT(r_b.find("X_TestObject") != string::npos); UT_ASSERT(r_b.find("id>27000627<") != string::npos); UT_ASSERT(r_b.find("id>9000309<") != string::npos); UT_ASSERT(r_b.find("result>1719<") != string::npos); UT_ASSERT(r_b.find("str>some string<") != string::npos); } static void TestWSMAN_Invoke_TestAllTypesWithSingleItemArray() { const char* c_Params = "\ false\ 90\ 13\ 14\ -9\ "; string r_b, r_h; SockSendRecvHTTP(s, false, _CreateInvokeRequestXML("MSFT_Person", "test/cpp", "TestAllTypes", c_Params, "777").c_str(), r_h, r_b ); // cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data UT_ASSERT(r_b.find("u8A>2<") != string::npos); UT_ASSERT(r_b.find("u8A>27<") != string::npos); UT_ASSERT(r_b.find("u8>91<") != string::npos); UT_ASSERT(r_b.find("b>TRUE<") != string::npos); UT_ASSERT(r_b.find("s16A>1<") != string::npos); UT_ASSERT(r_b.find("s16A>-9<") != string::npos); } /* verify array buffer re-allocation (16 items boundary)*/ static void TestWSMAN_Invoke_TestAllTypesWith17ItemsArray() { const char* c_Params = "\ 1\ 2\ 3\ 4\ 5\ 6\ 7\ 8\ 9\ 10\ 11\ 12\ 13\ 14\ 15\ 16\ 17\ "; string r_b, r_h; SockSendRecvHTTP(s, false, _CreateInvokeRequestXML("MSFT_Person", "test/cpp", "TestAllTypes", c_Params, "777").c_str(), r_h, r_b ); // cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data - number of elements and sum UT_ASSERT(r_b.find("u64A>17<") != string::npos); UT_ASSERT(r_b.find("u64A>153<") != string::npos); } /* verify array two buffer re-allocations (16 items boundary)*/ static void TestWSMAN_Invoke_TestAllTypesWith33ItemsArray() { const char* c_Params = "\ 1\ 2\ 3\ 4\ 5\ 6\ 7\ 8\ 9\ 10\ 11\ 12\ 13\ 14\ 15\ 16\ 17\ 18\ 19\ 20\ 21\ 22\ 23\ 24\ 25\ 26\ 27\ 28\ 29\ 30\ 31\ 32\ 33\ "; string r_b, r_h; SockSendRecvHTTP(s, false, _CreateInvokeRequestXML("MSFT_Person", "test/cpp", "TestAllTypes", c_Params, "777").c_str(), r_h, r_b ); // cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data - number of elements and sum UT_ASSERT(r_b.find("u64A>33<") != string::npos); UT_ASSERT(r_b.find("u64A>561<") != string::npos); } /* verify u64 type operations */ static void TestWSMAN_Invoke_TestAllTypesU64Max() { /*u64 max is 18446744073709551615; expect it as sum of two items */ const char* c_Params = "\ 18446744073709551610\ 5\ "; string r_b, r_h; SockSendRecvHTTP(s, false, _CreateInvokeRequestXML("MSFT_Person", "test/cpp", "TestAllTypes", c_Params, "777").c_str(), r_h, r_b ); // cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data - number of elements and sum UT_ASSERT(r_b.find("u64A>2<") != string::npos); UT_ASSERT(r_b.find("u64A>18446744073709551615<") != string::npos); } static void TestWSMAN_Invoke_TestAllTypesStringArray() { /* unit-test expects exactly two strings and retunr 3 strings: substrings form first two plus '*'*/ const char* c_Params = "\ 123456\ abcdef\ "; string r_b, r_h; SockSendRecvHTTP(s, false, _CreateInvokeRequestXML("MSFT_Person", "test/cpp", "TestAllTypes", c_Params, "777").c_str(), r_h, r_b ); // cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data - number of elements and sum UT_ASSERT(r_b.find("sA>456<") != string::npos); UT_ASSERT(r_b.find("sA>def<") != string::npos); UT_ASSERT(r_b.find("sA>*<") != string::npos); } static void TestWSMAN_Invoke_TestAllTypesReference() { /* unit-test expects a reference parameter and returns reference to the same class with key++ */ const char* c_Params = "\ \ \ http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous\ \ \ \ http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/MSFT_Base\ \ \ 89\ \ \ \ "; string r_b, r_h; SockSendRecvHTTP(s, false, _CreateInvokeRequestXML("MSFT_Person", "test/cpp", "TestAllTypes", c_Params, "777").c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data - number of elements and sum UT_ASSERT(r_b.find("Selector Name=\"Key\">90<") != string::npos); } static void TestWSMAN_Get_SmallNumber_17() { string r_b, r_h; SockSendRecvHTTP(s, false, _CreateGetRequestXML("X_smallNumber", "test/cpp", "17").c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data - number of elements and sum UT_ASSERT(r_b.find("http://schemas.xmlsoap.org/ws/2004/09/transfer/GetResponse17<") != string::npos); UT_ASSERT(r_b.find("SpelledNumber>seventeen<") != string::npos); } static void TestWSMAN_Get_SmallNumber_NotFound() { string r_b, r_h; SockSendRecvHTTP(s, false, _CreateGetRequestXML("X_smallNumber", "test/cpp", "17000").c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("500") != string::npos); UT_ASSERT(!r_b.empty()); // check data - number of elements and sum UT_ASSERT(r_b.find("CIM ERROR:NOT_FOUND") != string::npos); UT_ASSERT(r_b.find("Value>wsa:DestinationUnreachable<") != string::npos); } static void TestWSMAN_Get_MissingNamespace() { string r_b, r_h; SockSendRecvHTTP(s, false, _CreateGetRequestXML("X_smallNumber", "test/cpp", "17", false).c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("500") != string::npos); UT_ASSERT(!r_b.empty()); // check data - number of elements and sum UT_ASSERT(r_b.find(">CIM ERROR:INVALID_PARAMETER") != string::npos); UT_ASSERT(r_b.find("Value>wsman:InternalError<") != string::npos); } static void TestWSMAN_Delete_SmallNumber_7() { string r_b, r_h; SockSendRecvHTTP(s, false, _CreateDeleteRequestXML("X_smallNumber", "test/cpp", "7").c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data - number of elements and sum UT_ASSERT(r_b.find("http://schemas.xmlsoap.org/ws/2004/09/transfer/DeleteResponse17").c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("500") != string::npos); UT_ASSERT(!r_b.empty()); // check data - number of elements and sum UT_ASSERT(r_b.find("CIM ERROR:NOT_FOUND") != string::npos); UT_ASSERT(r_b.find("Value>wsa:DestinationUnreachable<") != string::npos); } static void TestWSMAN_Delete_MissingNamespace() { string r_b, r_h; SockSendRecvHTTP(s, false, _CreateDeleteRequestXML("X_smallNumber", "test/cpp", "7", false).c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("500") != string::npos); UT_ASSERT(!r_b.empty()); // check data - number of elements and sum UT_ASSERT(r_b.find(">CIM ERROR:INVALID_PARAMETER") != string::npos); UT_ASSERT(r_b.find("Value>wsman:InternalError<") != string::npos); } static void TestWSMAN_Create_SmallNumber_ok() { string r_b, r_h; const char* props = "" " text" " "; SockSendRecvHTTP(s, false, _CreateCreateRequestXML("X_smallNumber", "test/cpp", props).c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data - number of elements and sum UT_ASSERT(r_b.find("http://schemas.xmlsoap.org/ws/2004/09/transfer/CreateResponse10000<") != string::npos); UT_ASSERT(r_b.find("wxf:ResourceCreated>") != string::npos); } static void TestWSMAN_Create_SmallNumber_failed_invalid_prop() { /* invalid property set */ string r_b, r_h; const char* props = "" " text" " text" " "; SockSendRecvHTTP(s, false, _CreateCreateRequestXML("X_smallNumber", "test/cpp", props).c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("500") != string::npos); UT_ASSERT(!r_b.empty()); // check data - number of elements and sum UT_ASSERT(r_b.find("CIM ERROR:FAILED") != string::npos); } static void TestWSMAN_Create_SmallNumber_failed_no_description() { string r_b, r_h; const char* props = "" " 7" " "; SockSendRecvHTTP(s, false, _CreateCreateRequestXML("X_smallNumber", "test/cpp", props).c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("500") != string::npos); UT_ASSERT(!r_b.empty()); /* when description is not specified, provider returns 'not-found' */ // check data - UT_ASSERT(r_b.find("CIM ERROR:NOT_FOUND") != string::npos); } static void TestWSMAN_Create_SmallNumber_MissingNamespace() { string r_b, r_h; const char* props = "" " text" " "; SockSendRecvHTTP(s, false, _CreateCreateRequestXML("X_smallNumber", "test/cpp", props, false).c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("500") != string::npos); UT_ASSERT(!r_b.empty()); // check data - number of elements and sum UT_ASSERT(r_b.find(">CIM ERROR:INVALID_PARAMETER") != string::npos); UT_ASSERT(r_b.find("Value>wsman:InternalError<") != string::npos); } static void TestWSMAN_Modify_SmallNumber_ok() { string r_b, r_h; const char* props = "" " text" " "; const char* keys = "7"; SockSendRecvHTTP(s, false, _CreateModifyRequestXML("X_smallNumber", "test/cpp", keys, props).c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("200") != string::npos); UT_ASSERT(!r_b.empty()); // check data - number of elements and sum UT_ASSERT(r_b.find("http://schemas.xmlsoap.org/ws/2004/09/transfer/PutResponse10000<") != string::npos); UT_ASSERT(r_b.find("Description>text<") != string::npos); } static void TestWSMAN_Modify_SmallNumber_failed_invalid_prop() { /* invalid property set */ string r_b, r_h; const char* props = "" " text" " text" " "; const char* keys = "7"; SockSendRecvHTTP(s, false, _CreateModifyRequestXML("X_smallNumber", "test/cpp", keys, props).c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("500") != string::npos); UT_ASSERT(!r_b.empty()); // check data - number of elements and sum UT_ASSERT(r_b.find("CIM ERROR:FAILED") != string::npos); } static void TestWSMAN_Modify_SmallNumber_failed_no_description() { string r_b, r_h; const char* props = "" " Seven" " "; const char* keys = "7"; SockSendRecvHTTP(s, false, _CreateModifyRequestXML("X_smallNumber", "test/cpp", keys, props).c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("500") != string::npos); UT_ASSERT(!r_b.empty()); /* when description is not specified, provider returns 'not-found' */ // check data - UT_ASSERT(r_b.find("CIM ERROR:NOT_FOUND") != string::npos); } static void TestWSMAN_Modify_SmallNumber_MissingNamespace() { string r_b, r_h; const char* props = "" " text" " "; const char* keys = "7"; SockSendRecvHTTP(s, false, _CreateModifyRequestXML("X_smallNumber", "test/cpp", keys, props, false).c_str(), r_h, r_b ); //cout << "resp header: " << r_h << endl << endl << "body: " << r_b << endl; UT_ASSERT(r_h.find("500") != string::npos); UT_ASSERT(!r_b.empty()); // check data - number of elements and sum UT_ASSERT(r_b.find(">CIM ERROR:INVALID_PARAMETER") != string::npos); UT_ASSERT(r_b.find("Value>wsman:InternalError<") != string::npos); } void WSMAN_Tests_With_Server() { const char* namespaces[] = { "", "oop/requestor/" }; for (int KeepALive = 0; KeepALive < 2; KeepALive++) { s_DisconnectAfterEachTest = (KeepALive !=0 ); for (unsigned int i = 0; i < MI_COUNT(namespaces); i++) { s_currentNamespace = namespaces[i]; // general errors UT_TEST(TestWSMANemptyRequest); UT_TEST(TestWSMANInvalidXML); UT_TEST(TestWSMAN_NotSupportedEncoding); // wsman faults UT_TEST(TestWSMAN_Fault_invalidNamespace); UT_TEST(TestWSMAN_Fault_invalidClass); UT_TEST(TestWSMAN_Fault_instanceBiggerThaEnvelope); // enumeration UT_TEST(TestWSMAN_Enumerate_XProfile); UT_TEST(TestWSMAN_Enumerate_XProfile_EPR_Only); UT_TEST(TestWSMAN_Enumerate_XProfile_EPRAndObject); UT_TEST(TestWSMAN_Enumerate_X_SingletonWithAllTypes); UT_TEST(TestWSMAN_Enumerate_X_HugeNumberConformsToProfile); UT_TEST(TestWSMAN_Enumerate_MissingNamespace); // enumeration: deep/shallow/basic-props UT_TEST(TestWSMAN_Enumerate_X_HugeNumber_Deep); UT_TEST(TestWSMAN_Enumerate_X_HugeNumber_Shallow); UT_TEST(TestWSMAN_Enumerate_X_HugeNumber_BasicProps); // invoke UT_TEST(TestWSMAN_Invoke_SmallNumber_SpellNumber); UT_TEST(TestWSMAN_Invoke_SmallNumber_SpellNumber); UT_TEST(TestWSMAN_Invoke_TestEmbeddedObjectReturnKey20100609); UT_TEST(TestWSMAN_Invoke_TestEmbedded); UT_TEST(TestWSMAN_Invoke_TestEmbeddedWithArray); UT_TEST(TestWSMAN_Invoke_TestEmbeddedWithMultipleArrays); UT_TEST(TestWSMAN_Invoke_TestAllTypesWithSingleItemArray); UT_TEST(TestWSMAN_Invoke_TestAllTypesWith17ItemsArray); UT_TEST(TestWSMAN_Invoke_TestAllTypesWith33ItemsArray); UT_TEST(TestWSMAN_Invoke_TestAllTypesU64Max); UT_TEST(TestWSMAN_Invoke_TestAllTypesStringArray); UT_TEST(TestWSMAN_Invoke_TestAllTypesReference); UT_TEST(TestWSMAN_Invoke_MissingNamespace); // get UT_TEST(TestWSMAN_Get_SmallNumber_17); UT_TEST(TestWSMAN_Get_SmallNumber_NotFound); UT_TEST(TestWSMAN_Get_MissingNamespace); // delete UT_TEST(TestWSMAN_Delete_SmallNumber_7); UT_TEST(TestWSMAN_Delete_SmallNumber_17_NotFound); UT_TEST(TestWSMAN_Delete_MissingNamespace); // create UT_TEST(TestWSMAN_Create_SmallNumber_ok); UT_TEST(TestWSMAN_Create_SmallNumber_failed_invalid_prop); UT_TEST(TestWSMAN_Create_SmallNumber_failed_no_description); UT_TEST(TestWSMAN_Create_SmallNumber_MissingNamespace); // Put/Set/Modify UT_TEST(TestWSMAN_Modify_SmallNumber_ok); UT_TEST(TestWSMAN_Modify_SmallNumber_failed_invalid_prop); UT_TEST(TestWSMAN_Modify_SmallNumber_failed_no_description); UT_TEST(TestWSMAN_Modify_SmallNumber_MissingNamespace); } } s_currentNamespace = ""; // test out-of-process invocation static/non-static UT_TEST(TestWSMAN_Invoke_SmallNumber_SpellNumber_OOP); UT_TEST(TestWSMAN_Invoke_TestEmbeddedObjectReturnKey20100609_OOP); UT_TEST(TestWSMAN_Enumerate_XProfile); if (INVALID_SOCK != s) Sock_Close(s); s = INVALID_SOCK; }