diff options
-rwxr-xr-x | tests/common.c | 51 | ||||
-rwxr-xr-x | tests/common.h | 50 | ||||
-rw-r--r-- | tests/cunit/Makefile.am | 1 | ||||
-rw-r--r-- | tests/cunit/common.h | 3 | ||||
-rw-r--r-- | tests/cunit/enumeration.c | 2 | ||||
-rwxr-xr-x | tests/cunit/invoke.c | 251 | ||||
-rw-r--r-- | tests/cunit/run_tests.c | 1 | ||||
-rw-r--r-- | tests/cunit/transfer_get.c | 6 | ||||
-rwxr-xr-x | tests/cunit/transfer_put.c | 7 |
9 files changed, 271 insertions, 101 deletions
diff --git a/tests/common.c b/tests/common.c deleted file mode 100755 index dbd07cd..0000000 --- a/tests/common.c +++ /dev/null @@ -1,51 +0,0 @@ - - - -#include "wsman_config.h" - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <errno.h> -#include <time.h> - -#include "u/libu.h" -#include "wsman-client-api.h" -#include "wsman-xml-serializer.h" -#include "wsman-client-transport.h" - -#include "common.h" - - -WsManClient *cl; -char *host = "langley.home.planux.com"; - - - - -int init_test(void) { - wsman_client_transport_init(NULL); - if (getenv("OPENWSMAN_TEST_HOST")) { - host = getenv("OPENWSMAN_TEST_HOST"); - } - ServerData sd[] = { - {"localhost", 8889, "/wsman", "http", "wsman", "secret"} - }; - - cl = wsman_create_client( - sd[0].server, - sd[0].port, - sd[0].path, - sd[0].scheme, - sd[0].username, - sd[0].password); - return 0; -} - - -int clean_test(void) { - wsman_release_client(cl); - wsman_client_transport_fini(); - return 0; -} diff --git a/tests/common.h b/tests/common.h deleted file mode 100755 index f41f7ae..0000000 --- a/tests/common.h +++ /dev/null @@ -1,50 +0,0 @@ - -#ifndef _COMMON_H -#define _COMMON_H - -#include <CUnit/Basic.h> - -typedef struct { - const char *server; - int port; - const char *path; - const char *scheme; - const char *username; - const char *password; -} ServerData; - -typedef struct { - char *xpath_expr; - char *expected_value; -} XpathTest; - -typedef struct { - /* Explanation of what you should see */ - const char *explanation; - - /* Resource UR to test against */ - const char *resource_uri; - - /* Selectors in the form of a URI query key=value&key2=value2 */ - char *selectors; - - XpathTest xpath_test; - - /* What the final status code should be. */ - unsigned int final_status; - - unsigned char flags; - - unsigned int max_elements; - -} TestData; - -extern char *host; - -int init_test(void); -int clean_test(void); -int add_enumeration_tests(CU_pSuite ps); -int add_identify_tests(CU_pSuite ps); -int add_transfer_get_tests(CU_pSuite ps); - -#endif diff --git a/tests/cunit/Makefile.am b/tests/cunit/Makefile.am index 6cf5c94..a41d77a 100644 --- a/tests/cunit/Makefile.am +++ b/tests/cunit/Makefile.am @@ -12,6 +12,7 @@ wsman_cunit_tests_SOURCES = run_tests.c \ common.c \ common.h \ identify.c \ + invoke.c \ enumeration.c \ transfer_get.c \ transfer_put.c diff --git a/tests/cunit/common.h b/tests/cunit/common.h index ffbc5b0..86b2ff5 100644 --- a/tests/cunit/common.h +++ b/tests/cunit/common.h @@ -20,6 +20,8 @@ typedef struct { /* Resource UR to test against */ const char *resource_uri; + const char *method; + /* Selectors in the form of a URI query key=value&key2=value2 */ char *selectors; /* Properties in the form of a URI query key=value&key2=value2 */ @@ -49,5 +51,6 @@ int add_enumeration_tests(CU_pSuite ps); int add_identify_tests(CU_pSuite ps); int add_transfer_get_tests(CU_pSuite ps); int add_transfer_put_tests(CU_pSuite ps); +int add_invoke_tests(CU_pSuite ps); #endif diff --git a/tests/cunit/enumeration.c b/tests/cunit/enumeration.c index fa0c077..599c1ab 100644 --- a/tests/cunit/enumeration.c +++ b/tests/cunit/enumeration.c @@ -60,6 +60,7 @@ static TestData tests[] = { "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystemxx", NULL, NULL, + NULL, "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", "wsa:DestinationUnreachable", "/s:Envelope/s:Body/s:Fault/s:Detail/wsman:FaultDetail", @@ -73,6 +74,7 @@ static TestData tests[] = { "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", NULL, NULL, + NULL, "/s:Envelope/s:Header/wsman:TotalItemsCountEstimate", "3", NULL, diff --git a/tests/cunit/invoke.c b/tests/cunit/invoke.c new file mode 100755 index 0000000..f4dfe29 --- /dev/null +++ b/tests/cunit/invoke.c @@ -0,0 +1,251 @@ +/******************************************************************************* + * Copyright (C) 2004-2006 Intel Corp. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * - Neither the name of Intel Corp. nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL Intel Corp. OR THE CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + *******************************************************************************/ + +/** + * @author Anas Nashif + */ +#include "wsman_config.h" + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> +#include <time.h> + +#include "u/libu.h" +#include "wsman-client-api.h" +#include "wsman-client-transport.h" +#include "common.h" + + +TestData invoke_tests[] = { + { + "Custom Method without any selectors.", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + NULL, + NULL, + NULL, + "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", + "wsman:InvalidSelectors", + "/s:Envelope/s:Body/s:Fault/s:Detail/wsman:FaultDetail", + "http://schemas.dmtf.org/wbem/wsman/1/wsman/faultDetail/InsufficientSelectors", + 500, + 0, + 0 + }, + + { + "Custom Method with non existent Resource URI.", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystemxx", + NULL, + NULL, + NULL, + "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", + "wsa:DestinationUnreachable", + "/s:Envelope/s:Body/s:Fault/s:Detail/wsman:FaultDetail", + "http://schemas.dmtf.org/wbem/wsman/1/wsman/faultDetail/InvalidResourceURI", + 500, + 0, + 0 + }, + + { + "Custom Method with unsufficient selectors.", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + NULL, + "Name=%s", + NULL, + "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", + "wsman:InvalidSelectors", + "/s:Envelope/s:Body/s:Fault/s:Detail/wsman:FaultDetail", + "http://schemas.dmtf.org/wbem/wsman/1/wsman/faultDetail/InsufficientSelectors", + 500, + 0, + 0 + }, + + { + "Custom Method with wrong selectors.", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + NULL, + "CreationClassName=OpenWBEM_UnitaryComputerSystem&Namex=%s", + NULL, + "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", + "wsman:InvalidSelectors", + "/s:Envelope/s:Body/s:Fault/s:Detail/wsman:FaultDetail", + "http://schemas.dmtf.org/wbem/wsman/1/wsman/faultDetail/UnexpectedSelectors", + 500, + 0, + 0 + }, + + { + "Custom Method with all selectors but with wrong values.", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + NULL, + "CreationClassName=OpenWBEM_UnitaryComputerSystem&Name=%sx", + NULL, + "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", + "wsa:DestinationUnreachable", + "/s:Envelope/s:Body/s:Fault/s:Detail/wsman:FaultDetail", + "http://schemas.dmtf.org/wbem/wsman/1/wsman/faultDetail/InvalidResourceURI", + 500, + 0, + 0 + }, + { + "Custom Method with correct selectors and parameters check for new value", + "http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_TimeZoneSettingData", + NULL, + "InstanceID=omc:timezone", + "TimeZone=US/Pacific", + "/s:Envelope/s:Body/p:OMC_TimeZoneSettingData/p:TimeZone", + "US/Pacific", + NULL, + NULL, + 200, + FLAG_DUMP_REQUEST, + }, + { + "Custom Method with correct selectors and parameters reset value", + "http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_TimeZoneSettingData", + NULL, + "InstanceID=omc:timezone", + "TimeZone=US/Eastern", + "/s:Envelope/s:Body/p:OMC_TimeZoneSettingData/p:TimeZone", + "US/Eastern", + NULL, + NULL, + 200, + 0, + }, +}; + +static int ntests = sizeof (invoke_tests) / sizeof (invoke_tests[0]); + + + +extern WsManClient *cl; +actionOptions options; + +static void invoke_test() { + WsXmlDocH doc; + char *xpf = NULL; + char *xpd = NULL; + static int i = 0; // executed test number. + char *old_selectors = invoke_tests[i].selectors; + + + if (invoke_tests[i].selectors) { + invoke_tests[i].selectors = + u_strdup_printf(invoke_tests[i].selectors, host, host, host); + } + + reinit_client_connection(cl); + initialize_action_options(&options); + + if (invoke_tests[i].selectors != NULL) { + wsman_add_selectors_from_query_string (&options, invoke_tests[i].selectors); + } + if (invoke_tests[i].properties != NULL) { + wsman_add_properties_from_query_string (&options, invoke_tests[i].properties); + } + options.flags = invoke_tests[i].flags; + + + doc = wsman_invoke (cl, (char *)invoke_tests[i].resource_uri, (char *)invoke_tests[i].method, options); + CU_ASSERT_TRUE(wsman_get_client_response_code(cl) == invoke_tests[i].final_status); + + CU_ASSERT_PTR_NOT_NULL(doc); + if (!doc) { + goto RETURN; + } + if (invoke_tests[i].expr1 == NULL) { + goto RETURN; + } + CU_ASSERT_PTR_NOT_NULL(invoke_tests[i].value1); + if (invoke_tests[i].value1 == NULL) { + goto RETURN; + } + xpf = ws_xml_get_xpath_value(doc, invoke_tests[i].expr1); + CU_ASSERT_PTR_NOT_NULL(xpf); + if (!xpf) { + goto RETURN; + } + CU_ASSERT_STRING_EQUAL(xpf, invoke_tests[i].value1); + + if (strcmp(xpf, invoke_tests[i].value1)) { + //printf("Expected %s; returned %s\n", + // invoke_tests[i].value1, xpf); + goto RETURN; + } + if (invoke_tests[i].expr2 == NULL) { + goto RETURN; + } + xpd = ws_xml_get_xpath_value(doc, invoke_tests[i].expr2); + CU_ASSERT_PTR_NOT_NULL(xpd); + if (!xpd) { + goto RETURN; + } + CU_ASSERT_PTR_NOT_NULL(invoke_tests[i].value2); + if (invoke_tests[i].value2 == NULL) { + goto RETURN; + } + CU_ASSERT_STRING_EQUAL(xpd, invoke_tests[i].value2 ); + if (strcmp(xpd, invoke_tests[i].value2)) { + goto RETURN; + } +RETURN: + u_free(xpf); + u_free(xpd); + if (doc) { + ws_xml_destroy_doc(doc); + } + u_free((char *)invoke_tests[i].selectors); + invoke_tests[i].selectors = old_selectors; + destroy_action_options(&options); + i++; // increase executed test number +} + + + + +int add_invoke_tests(CU_pSuite ps) { + int found_test = 0; + int i; + /* add the tests to the suite */ + for (i =0; i < ntests; i++) { + found_test += (NULL != CU_add_test(ps, invoke_tests[i].explanation, + (CU_TestFunc)invoke_test)); + } + return (found_test > 0); +} + diff --git a/tests/cunit/run_tests.c b/tests/cunit/run_tests.c index bba040b..5f51e9c 100644 --- a/tests/cunit/run_tests.c +++ b/tests/cunit/run_tests.c @@ -53,6 +53,7 @@ setup_client_suite(void) { num_tests += add_identify_tests(ps); num_tests += add_transfer_get_tests(ps); num_tests += add_transfer_put_tests(ps); + num_tests += add_invoke_tests(ps); if (num_tests == 0) { printf("No tests to run\n"); // nothing to do diff --git a/tests/cunit/transfer_get.c b/tests/cunit/transfer_get.c index 269e668..66554ca 100644 --- a/tests/cunit/transfer_get.c +++ b/tests/cunit/transfer_get.c @@ -52,6 +52,7 @@ TestData get_tests[] = { "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", NULL, NULL, + NULL, "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", "wsman:InvalidSelectors", "/s:Envelope/s:Body/s:Fault/s:Detail/wsman:FaultDetail", @@ -64,6 +65,7 @@ TestData get_tests[] = { { "Transfer Get with non existent Resource URI.", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystemxx", + NULL, NULL, NULL, "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", @@ -78,6 +80,7 @@ TestData get_tests[] = { { "Transfer Get with unsufficient selectors.", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + NULL, "Name=%s", NULL, "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", @@ -92,6 +95,7 @@ TestData get_tests[] = { { "Transfer Get with wrong selectors.", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + NULL, "CreationClassName=OpenWBEM_UnitaryComputerSystem&Namex=%s", NULL, "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", @@ -106,6 +110,7 @@ TestData get_tests[] = { { "Transfer Get with all selectors but with wrong values 1.", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + NULL, "CreationClassName=OpenWBEM_UnitaryComputerSystem&Name=%sx", NULL, "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", @@ -119,6 +124,7 @@ TestData get_tests[] = { { "Transfer Get with correct selectors. Check response code", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + NULL, "CreationClassName=OpenWBEM_UnitaryComputerSystem&Name=%s", NULL, NULL, diff --git a/tests/cunit/transfer_put.c b/tests/cunit/transfer_put.c index 069db32..42625f8 100755 --- a/tests/cunit/transfer_put.c +++ b/tests/cunit/transfer_put.c @@ -52,6 +52,7 @@ TestData put_tests[] = { "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", NULL, NULL, + NULL, "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", "wsman:InvalidSelectors", "/s:Envelope/s:Body/s:Fault/s:Detail/wsman:FaultDetail", @@ -64,6 +65,7 @@ TestData put_tests[] = { { "Transfer Put with non existent Resource URI.", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystemxx", + NULL, NULL, NULL, "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", @@ -78,6 +80,7 @@ TestData put_tests[] = { { "Transfer Put with unsufficient selectors.", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + NULL, "Name=%s", NULL, "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", @@ -92,6 +95,7 @@ TestData put_tests[] = { { "Transfer Put with wrong selectors.", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + NULL, "CreationClassName=OpenWBEM_UnitaryComputerSystem&Namex=%s", NULL, "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", @@ -106,6 +110,7 @@ TestData put_tests[] = { { "Transfer Put with all selectors but with wrong values.", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + NULL, "CreationClassName=OpenWBEM_UnitaryComputerSystem&Name=%sx", NULL, "/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value", @@ -119,6 +124,7 @@ TestData put_tests[] = { { "Transfer Put with correct selectors and parameters check for new value", "http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_TimeZoneSettingData", + NULL, "InstanceID=omc:timezone", "TimeZone=US/Pacific", "/s:Envelope/s:Body/p:OMC_TimeZoneSettingData/p:TimeZone", @@ -131,6 +137,7 @@ TestData put_tests[] = { { "Transfer Put with correct selectors and parameters reset value", "http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_TimeZoneSettingData", + NULL, "InstanceID=omc:timezone", "TimeZone=US/Eastern", "/s:Envelope/s:Body/p:OMC_TimeZoneSettingData/p:TimeZone", |