From 0ff8639d03248af1174a760e7a0a0fb9c158ad99 Mon Sep 17 00:00:00 2001 From: Anas Nashif Date: Mon, 20 Nov 2006 17:41:40 +0000 Subject: moved cunit tests to client where they belong --- Makefile.am | 2 +- configure.in | 5 + tests/.cvsignore | 2 + tests/Makefile.am | 5 + tests/common.c | 51 ++++++++++ tests/common.h | 53 ++++++++++ tests/cunit/.cvsignore | 8 ++ tests/cunit/Makefile.am | 19 ++++ tests/cunit/common.c | 51 ++++++++++ tests/cunit/common.h | 53 ++++++++++ tests/cunit/enumeration.c | 221 +++++++++++++++++++++++++++++++++++++++++ tests/cunit/identify.c | 152 +++++++++++++++++++++++++++++ tests/cunit/run_tests.c | 90 +++++++++++++++++ tests/cunit/transfer_get.c | 238 +++++++++++++++++++++++++++++++++++++++++++++ 14 files changed, 949 insertions(+), 1 deletion(-) create mode 100644 tests/.cvsignore create mode 100644 tests/Makefile.am create mode 100755 tests/common.c create mode 100755 tests/common.h create mode 100644 tests/cunit/.cvsignore create mode 100644 tests/cunit/Makefile.am create mode 100755 tests/cunit/common.c create mode 100755 tests/cunit/common.h create mode 100644 tests/cunit/enumeration.c create mode 100755 tests/cunit/identify.c create mode 100644 tests/cunit/run_tests.c create mode 100755 tests/cunit/transfer_get.c diff --git a/Makefile.am b/Makefile.am index f6a25a0..79f6d9c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = src +SUBDIRS = src tests package: dist cp wsmancli.spec /usr/src/packages/SPEC diff --git a/configure.in b/configure.in index 40e1eb6..2a64dda 100644 --- a/configure.in +++ b/configure.in @@ -15,10 +15,15 @@ WSMAN_PKG=$PACKAGE_NAME AC_SUBST(WSMAN_PKG) PKG_CHECK_MODULES(OPENWSMAN, [openwsman >= 0.0.0]) +have_cunit=no +AC_CHECK_HEADERS([CUnit/Basic.h], have_cunit="yes" ) +AM_CONDITIONAL(BUILD_CUNIT_TESTS, test "$have_cunit" == "yes") AC_OUTPUT([ wsmancli.spec Makefile src/Makefile + tests/Makefile + tests/cunit/Makefile ]) diff --git a/tests/.cvsignore b/tests/.cvsignore new file mode 100644 index 0000000..3dda729 --- /dev/null +++ b/tests/.cvsignore @@ -0,0 +1,2 @@ +Makefile.in +Makefile diff --git a/tests/Makefile.am b/tests/Makefile.am new file mode 100644 index 0000000..d311b0d --- /dev/null +++ b/tests/Makefile.am @@ -0,0 +1,5 @@ +SUBDIRS = + +if BUILD_CUNIT_TESTS +SUBDIRS += cunit +endif diff --git a/tests/common.c b/tests/common.c new file mode 100755 index 0000000..dbd07cd --- /dev/null +++ b/tests/common.c @@ -0,0 +1,51 @@ + + + +#include "wsman_config.h" + +#include +#include +#include +#include +#include +#include + +#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 new file mode 100755 index 0000000..fdfb160 --- /dev/null +++ b/tests/common.h @@ -0,0 +1,53 @@ + +#ifndef _COMMON_H +#define _COMMON_H + +#include + +typedef struct { + const char *server; + int port; + const char *path; + const char *scheme; + const char *username; + const char *password; +} ServerData; + +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; + + /* Fault Value */ + char* fault_expr; + char* fault_value; + + /* Fault detail */ + char *detail_expr; + char *detail_value; + + + + /* 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/.cvsignore b/tests/cunit/.cvsignore new file mode 100644 index 0000000..884b0f3 --- /dev/null +++ b/tests/cunit/.cvsignore @@ -0,0 +1,8 @@ +Makefile +Makefile.in +*.o +*.lo +*.la +.deps +.libs +wsman diff --git a/tests/cunit/Makefile.am b/tests/cunit/Makefile.am new file mode 100644 index 0000000..1e5c0e5 --- /dev/null +++ b/tests/cunit/Makefile.am @@ -0,0 +1,19 @@ +AM_CFLAGS = @CFLAGS@ + +INCLUDES = \ + $(OPENWSMAN_CFLAGS) + + +wsman_cunit_tests_LDADD = \ + $(OPENWSMAN_LIBS) -lcunit -lcurl + + +wsman_cunit_tests_SOURCES = run_tests.c \ + common.c \ + common.h \ + identify.c \ + enumeration.c \ + transfer_get.c + +noinst_PROGRAMS = wsman_cunit_tests + diff --git a/tests/cunit/common.c b/tests/cunit/common.c new file mode 100755 index 0000000..dbd07cd --- /dev/null +++ b/tests/cunit/common.c @@ -0,0 +1,51 @@ + + + +#include "wsman_config.h" + +#include +#include +#include +#include +#include +#include + +#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/cunit/common.h b/tests/cunit/common.h new file mode 100755 index 0000000..fdfb160 --- /dev/null +++ b/tests/cunit/common.h @@ -0,0 +1,53 @@ + +#ifndef _COMMON_H +#define _COMMON_H + +#include + +typedef struct { + const char *server; + int port; + const char *path; + const char *scheme; + const char *username; + const char *password; +} ServerData; + +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; + + /* Fault Value */ + char* fault_expr; + char* fault_value; + + /* Fault detail */ + char *detail_expr; + char *detail_value; + + + + /* 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/enumeration.c b/tests/cunit/enumeration.c new file mode 100644 index 0000000..469b91b --- /dev/null +++ b/tests/cunit/enumeration.c @@ -0,0 +1,221 @@ +/******************************************************************************* + * 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 + * @author Nathan Rakoff + */ +#include "wsman_config.h" + +#include +#include +#include +#include +#include +#include + +#include "u/libu.h" + +#include "wsman-client-api.h" +#include "wsman-client-transport.h" +#include "wsman-debug.h" +#include "common.h" + + + +static int _debug = 0; + + + +static TestData tests[] = { + { + "Enumeration with non existent Resource URI.", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystemxx", + 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, + FLAG_NONE, + 0 + }, + + { + "Enumeration with valid Resource URI and Items Count Estimation.", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + NULL, + "/s:Envelope/s:Header/wsman:TotalItemsCountEstimate", + "3", + NULL, + NULL, + 200, + FLAG_ENUMERATION_COUNT_ESTIMATION, + 0 + }, /* + { + "Enumeration with valid Resource URI.", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + NULL, + 200, + FLAG_NONE, + 0 + }, + { + "Enumeration with valid Resource URI and additional invalid selectors.", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + NULL, + 200, + FLAG_NONE, + 1 + }, + { + "Enumeration with valid Resource URI/Count Estimation.", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + NULL, + 200, + FLAG_ENUMERATION_COUNT_ESTIMATION, + 0 + }, + { + "Enumeration with valid Resource URI/Optimization.", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + NULL, + 200, + FLAG_ENUMERATION_OPTIMIZATION, + 0 + }, + { + "Enumeration with Count Estimation/Optimzation and get all elements.", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + NULL, + 200, + FLAG_ENUMERATION_OPTIMIZATION | FLAG_ENUMERATION_COUNT_ESTIMATION, + 10 + + }, + { + "Enumeration with Count Estimation/Optimzation/Epr and get all elements.", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + NULL, + 200, + FLAG_ENUMERATION_OPTIMIZATION | FLAG_ENUMERATION_COUNT_ESTIMATION | FLAG_ENUMERATION_ENUM_EPR, + 10 + + }, + { + "Enumeration with Count Estimation/Optimzation/ObjAndEpr and get all elements.", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + NULL, + 200, + FLAG_ENUMERATION_OPTIMIZATION | FLAG_ENUMERATION_COUNT_ESTIMATION | FLAG_ENUMERATION_ENUM_OBJ_AND_EPR, + 10 + + } */ +}; + + +static int ntests = sizeof (tests) / sizeof (tests[0]); + + +extern WsManClient *cl; + +/* +static void wsman_output(WsXmlDocH doc) { + if (doc) + ws_xml_dump_node_tree(stdout, ws_xml_get_doc_root(doc)); + else + printf("returned doc is null\n"); + return; +} +*/ + +actionOptions options; + + + +static void enumeration_test() { + char *enumContext = NULL; + static int i = 0; + char *xp = NULL; + + reinit_client_connection(cl); + initialize_action_options(&options); + + options.flags = tests[i].flags; + + if (tests[i].selectors != NULL) + wsman_add_selectors_from_query_string(&options, tests[i].selectors); + + options.max_elements = tests[i].max_elements; + WsXmlDocH enum_response = wsenum_enumerate(cl, + (char *)tests[i].resource_uri, options); + CU_ASSERT_TRUE(wsman_get_client_response_code(cl) == tests[i].final_status ); + if (enum_response) { + enumContext = wsenum_get_enum_context(enum_response); + } else { + enumContext = NULL; + } + + if (_debug) wsman_output(enum_response); + + if (tests[i].fault_expr == NULL) { + goto RETURN; + } + xp = ws_xml_get_xpath_value(enum_response, tests[i].fault_expr); + CU_ASSERT_PTR_NOT_NULL(xp); + if (!xp) { + goto RETURN; + } + CU_ASSERT_STRING_EQUAL(xp, tests[i].fault_value ); + +RETURN: + if (enum_response) { + ws_xml_destroy_doc(enum_response); + } + u_free(xp); + destroy_action_options(&options); + i++; // decrease executed test number +} + + +int add_enumeration_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, + tests[i].explanation, enumeration_test)); + } + return (found_test > 0); +} + + diff --git a/tests/cunit/identify.c b/tests/cunit/identify.c new file mode 100755 index 0000000..dafaf41 --- /dev/null +++ b/tests/cunit/identify.c @@ -0,0 +1,152 @@ +/******************************************************************************* + * 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 +#include +#include +#include +#include +#include + +#include "u/libu.h" +#include "wsman-errors.h" +#include "wsman-client-api.h" +#include "wsman-client-transport.h" +#include "common.h" + + + + + + +static TestData tests[] = { + { + "Testing Identify Request, check protocol version", + NULL, + NULL, + "/s:Envelope/s:Body/wsmid:IdentifyResponse/wsmid:ProtocolVersion", + XML_NS_WS_MAN, + NULL, + NULL, + 200, + FLAG_NONE, + 0 + }, + { + "Testing Identify Request, check product version", + NULL, + NULL, + "/s:Envelope/s:Body/wsmid:IdentifyResponse/wsmid:ProductVersion", + PACKAGE_VERSION, + NULL, + NULL, + 200, + FLAG_NONE, + 0 + }, + { + "Testing Identify Request, check product vendor", + NULL, + NULL, + "/s:Envelope/s:Body/wsmid:IdentifyResponse/wsmid:ProductVendor", + "Openwsman Project", + NULL, + NULL, + 200, + FLAG_NONE, + 0 + } +}; + + +static int ntests = sizeof (tests) / sizeof (tests[0]); + + +extern WsManClient *cl; +actionOptions options; + + + +static void +identify_test() { + + WsXmlDocH response; + static int i = 0; + char *xp = NULL; + + reinit_client_connection(cl); + initialize_action_options(&options); + + response = wsman_identify(cl, options); + CU_ASSERT_TRUE(wsman_get_client_response_code(cl) == tests[i].final_status); + + CU_ASSERT_PTR_NOT_NULL(response); + if (response == NULL) { + goto RETURN; + } + + if (tests[i].fault_value != NULL) { + xp = ws_xml_get_xpath_value(response, tests[i].fault_expr); + CU_ASSERT_PTR_NOT_NULL(xp); + if (xp) { + CU_ASSERT_STRING_EQUAL(xp, tests[i].fault_value ); + } + } + +RETURN: + if (response) { + ws_xml_destroy_doc(response); + } + u_free(xp); + destroy_action_options(&options); + i++; +} + + + +int add_identify_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, + tests[i].explanation, identify_test)); + } + + return (found_test > 0); +} + + diff --git a/tests/cunit/run_tests.c b/tests/cunit/run_tests.c new file mode 100644 index 0000000..a55eb90 --- /dev/null +++ b/tests/cunit/run_tests.c @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (C) 2004-2006 Dell Inc. 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 Dell Inc. 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 Nathan Rakoff + */ +#include +#include "common.h" + +#define TRUE 1 +#define FALSE 0 + + +static CU_pSuite +setup_client_suite(void) { + int num_tests = 0; + /* add a suite to the registry */ + CU_pSuite ps = CU_add_suite("OpenWSman Client Library Tests", + init_test, clean_test); + if (NULL == ps) { + return NULL; + } + + /* add the tests to the suite */ + num_tests += add_enumeration_tests(ps); + num_tests += add_identify_tests(ps); + num_tests += add_transfer_get_tests(ps); + if (num_tests == 0) { + printf("No tests to run\n"); + // nothing to do + return NULL; + } + return ps; +} + + + +int +main(int argc, char** argv) { + CU_pSuite pSuite = NULL; + + /* initialize the CUnit test registry */ + if (CUE_SUCCESS != CU_initialize_registry()) + return CU_get_error(); + + /* add client suite to the registry */ + pSuite = (CU_pSuite)setup_client_suite(); + if (NULL == pSuite) { + CU_cleanup_registry(); + return CU_get_error(); + } + + /* Run all tests using the basic interface */ + CU_basic_set_mode(CU_BRM_VERBOSE); + CU_basic_run_tests(); + printf("\n"); + CU_basic_show_failures(CU_get_failure_list()); + printf("\n\n"); + + /* Clean up registry and return */ + CU_cleanup_registry(); + return CU_get_error(); +} diff --git a/tests/cunit/transfer_get.c b/tests/cunit/transfer_get.c new file mode 100755 index 0000000..8f3c65d --- /dev/null +++ b/tests/cunit/transfer_get.c @@ -0,0 +1,238 @@ +/******************************************************************************* + * 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 +#include +#include +#include +#include +#include + +#include "u/libu.h" +#include "wsman-client-api.h" +#include "wsman-client-transport.h" +#include "common.h" + + +TestData get_tests[] = { + { + "Transfer Get without any selectors.", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + 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 + }, + + { + "Transfer Get with non existent Resource URI.", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystemxx", + 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 + }, + + { + "Transfer Get with unsufficient selectors.", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + "Name=%s", + "/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 + }, + + { + "Transfer Get with wrong selectors.", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + "CreationClassName=OpenWBEM_UnitaryComputerSystem&Namex=%s", + "/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 + }, + + { + "Transfer Get with all selectors but with wrong values 1.", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + "CreationClassName=OpenWBEM_UnitaryComputerSystem&Name=%sx", + "/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/InvalidValue", + 500, + 0, + 0 + }, + { + "Transfer Get with all selectors but with wrong values 2.", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + "CreationClassName=OpenWBEM_UnitaryComputerSystemx&Name=%s", + "/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/InvalidValue", + 500, + 0, + 0 + }, + { + "Transfer Get with correct selectors. Check response code", + "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem", + "CreationClassName=OpenWBEM_UnitaryComputerSystem&Name=%s", + NULL, + NULL, + NULL, + NULL, + 200, + 0, + }, +}; + +static int ntests = sizeof (get_tests) / sizeof (get_tests[0]); + + + +extern WsManClient *cl; +actionOptions options; + +static void transfer_get_test() { + WsXmlDocH doc; + char *xpf = NULL; + char *xpd = NULL; + static int i = 0; // executed test number. + char *old_selectors = get_tests[i].selectors; + + + if (get_tests[i].selectors) { + get_tests[i].selectors = + u_strdup_printf(get_tests[i].selectors, host, host, host); + } + + reinit_client_connection(cl); + initialize_action_options(&options); + + if (get_tests[i].selectors != NULL) { + wsman_add_selectors_from_query_string (&options, get_tests[i].selectors); + } + + + doc = ws_transfer_get(cl, (char *)get_tests[i].resource_uri, options); + CU_ASSERT_TRUE(wsman_get_client_response_code(cl) == get_tests[i].final_status); + + CU_ASSERT_PTR_NOT_NULL(doc); + if (!doc) { + goto RETURN; + } + + if (get_tests[i].fault_expr == NULL) { + goto RETURN; + } + CU_ASSERT_PTR_NOT_NULL(get_tests[i].fault_value); + if (get_tests[i].fault_value == NULL) { + goto RETURN; + } + xpf = ws_xml_get_xpath_value(doc, get_tests[i].fault_expr); + CU_ASSERT_PTR_NOT_NULL(xpf); + if (!xpf) { + goto RETURN; + } + CU_ASSERT_STRING_EQUAL(xpf, get_tests[i].fault_value); + + if (strcmp(xpf, get_tests[i].fault_value)) { + //printf("Expected %s; returned %s\n", + // get_tests[i].fault_value, xpf); + goto RETURN; + } + if (get_tests[i].detail_expr == NULL) { + goto RETURN; + } + xpd = ws_xml_get_xpath_value(doc, get_tests[i].detail_expr); + CU_ASSERT_PTR_NOT_NULL(xpd); + if (!xpd) { + goto RETURN; + } + CU_ASSERT_PTR_NOT_NULL(get_tests[i].detail_value); + if (get_tests[i].detail_value == NULL) { + goto RETURN; + } + CU_ASSERT_STRING_EQUAL(xpd, get_tests[i].detail_value ); + if (strcmp(xpd, get_tests[i].detail_value)) { + //printf("Expected %s; returned %s\n", + // get_tests[i].detail_value, xpd); + goto RETURN; + } + +RETURN: + u_free(xpf); + u_free(xpd); + if (doc) { + ws_xml_destroy_doc(doc); + } + u_free((char *)get_tests[i].selectors); + get_tests[i].selectors = old_selectors; + destroy_action_options(&options); + i++; // increase executed test number +} + + + + +int add_transfer_get_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, get_tests[i].explanation, + (CU_TestFunc)transfer_get_test)); + } + return (found_test > 0); +} + -- cgit