summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnas Nashif <nashif@intel.com>2006-11-21 03:51:05 +0000
committerAnas Nashif <nashif@intel.com>2006-11-21 03:51:05 +0000
commitbb32e264e689cfc25dcb223bcf66e1a401963153 (patch)
treece2a45d389877b4a706d33642e46321e6876b8ab
parentff14296d2a7c0564b4764112cbaf03ca5703381c (diff)
downloadwsmancli-bb32e264e689cfc25dcb223bcf66e1a401963153.tar.gz
wsmancli-bb32e264e689cfc25dcb223bcf66e1a401963153.tar.xz
wsmancli-bb32e264e689cfc25dcb223bcf66e1a401963153.zip
more testcases
-rwxr-xr-xtests/common.h17
-rw-r--r--tests/cunit/Makefile.am3
-rw-r--r--tests/cunit/common.h14
-rw-r--r--tests/cunit/enumeration.c21
-rw-r--r--tests/cunit/identify.c20
-rw-r--r--tests/cunit/run_tests.c1
-rw-r--r--tests/cunit/transfer_get.c32
-rwxr-xr-xtests/cunit/transfer_put.c231
8 files changed, 276 insertions, 63 deletions
diff --git a/tests/common.h b/tests/common.h
index fdfb160..f41f7ae 100755
--- a/tests/common.h
+++ b/tests/common.h
@@ -13,7 +13,12 @@ typedef struct {
const char *password;
} ServerData;
-typedef struct {
+typedef struct {
+ char *xpath_expr;
+ char *expected_value;
+} XpathTest;
+
+typedef struct {
/* Explanation of what you should see */
const char *explanation;
@@ -23,15 +28,7 @@ typedef struct {
/* 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;
-
-
+ XpathTest xpath_test;
/* What the final status code should be. */
unsigned int final_status;
diff --git a/tests/cunit/Makefile.am b/tests/cunit/Makefile.am
index 1e5c0e5..6cf5c94 100644
--- a/tests/cunit/Makefile.am
+++ b/tests/cunit/Makefile.am
@@ -13,7 +13,8 @@ wsman_cunit_tests_SOURCES = run_tests.c \
common.h \
identify.c \
enumeration.c \
- transfer_get.c
+ transfer_get.c \
+ transfer_put.c
noinst_PROGRAMS = wsman_cunit_tests
diff --git a/tests/cunit/common.h b/tests/cunit/common.h
index fdfb160..ffbc5b0 100644
--- a/tests/cunit/common.h
+++ b/tests/cunit/common.h
@@ -22,15 +22,14 @@ typedef struct {
/* 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 */
+ char *properties;
- /* Fault Value */
- char* fault_expr;
- char* fault_value;
-
- /* Fault detail */
- char *detail_expr;
- char *detail_value;
+ char* expr1;
+ char* value1;
+ char *expr2;
+ char *value2;
/* What the final status code should be. */
@@ -49,5 +48,6 @@ 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);
+int add_transfer_put_tests(CU_pSuite ps);
#endif
diff --git a/tests/cunit/enumeration.c b/tests/cunit/enumeration.c
index 469b91b..fa0c077 100644
--- a/tests/cunit/enumeration.c
+++ b/tests/cunit/enumeration.c
@@ -59,6 +59,7 @@ static TestData tests[] = {
"Enumeration with non existent Resource URI.",
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystemxx",
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",
@@ -67,11 +68,11 @@ static TestData tests[] = {
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,
+ NULL,
"/s:Envelope/s:Header/wsman:TotalItemsCountEstimate",
"3",
NULL,
@@ -147,20 +148,8 @@ 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;
@@ -186,15 +175,15 @@ static void enumeration_test() {
if (_debug) wsman_output(enum_response);
- if (tests[i].fault_expr == NULL) {
+ if (tests[i].expr1 == NULL) {
goto RETURN;
}
- xp = ws_xml_get_xpath_value(enum_response, tests[i].fault_expr);
+ xp = ws_xml_get_xpath_value(enum_response, tests[i].expr1);
CU_ASSERT_PTR_NOT_NULL(xp);
if (!xp) {
goto RETURN;
}
- CU_ASSERT_STRING_EQUAL(xp, tests[i].fault_value );
+ CU_ASSERT_STRING_EQUAL(xp, tests[i].value1 );
RETURN:
if (enum_response) {
diff --git a/tests/cunit/identify.c b/tests/cunit/identify.c
index dafaf41..822682e 100644
--- a/tests/cunit/identify.c
+++ b/tests/cunit/identify.c
@@ -56,22 +56,11 @@ static TestData tests[] = {
"Testing Identify Request, check protocol version",
NULL,
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
@@ -80,6 +69,7 @@ static TestData tests[] = {
"Testing Identify Request, check product vendor",
NULL,
NULL,
+ NULL,
"/s:Envelope/s:Body/wsmid:IdentifyResponse/wsmid:ProductVendor",
"Openwsman Project",
NULL,
@@ -117,11 +107,11 @@ identify_test() {
goto RETURN;
}
- if (tests[i].fault_value != NULL) {
- xp = ws_xml_get_xpath_value(response, tests[i].fault_expr);
+ if (tests[i].value1 != NULL) {
+ xp = ws_xml_get_xpath_value(response, tests[i].expr1);
CU_ASSERT_PTR_NOT_NULL(xp);
if (xp) {
- CU_ASSERT_STRING_EQUAL(xp, tests[i].fault_value );
+ CU_ASSERT_STRING_EQUAL(xp, tests[i].value1 );
}
}
diff --git a/tests/cunit/run_tests.c b/tests/cunit/run_tests.c
index a55eb90..bba040b 100644
--- a/tests/cunit/run_tests.c
+++ b/tests/cunit/run_tests.c
@@ -52,6 +52,7 @@ setup_client_suite(void) {
num_tests += add_enumeration_tests(ps);
num_tests += add_identify_tests(ps);
num_tests += add_transfer_get_tests(ps);
+ num_tests += add_transfer_put_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 49c91de..269e668 100644
--- a/tests/cunit/transfer_get.c
+++ b/tests/cunit/transfer_get.c
@@ -51,6 +51,7 @@ TestData get_tests[] = {
"Transfer Get without any selectors.",
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem",
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,
"/s:Envelope/s:Body/s:Fault/s:Code/s:Subcode/s:Value",
"wsa:DestinationUnreachable",
"/s:Envelope/s:Body/s:Fault/s:Detail/wsman:FaultDetail",
@@ -77,6 +79,7 @@ TestData get_tests[] = {
"Transfer Get with unsufficient selectors.",
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem",
"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",
@@ -90,6 +93,7 @@ TestData get_tests[] = {
"Transfer Get with wrong selectors.",
"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem",
"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",
@@ -103,6 +107,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",
"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",
@@ -119,6 +124,7 @@ TestData get_tests[] = {
NULL,
NULL,
NULL,
+ NULL,
200,
0,
},
@@ -160,39 +166,37 @@ static void transfer_get_test() {
goto RETURN;
}
- if (get_tests[i].fault_expr == NULL) {
+ if (get_tests[i].expr1 == NULL) {
goto RETURN;
}
- CU_ASSERT_PTR_NOT_NULL(get_tests[i].fault_value);
- if (get_tests[i].fault_value == NULL) {
+ CU_ASSERT_PTR_NOT_NULL(get_tests[i].value1);
+ if (get_tests[i].value1 == NULL) {
goto RETURN;
}
- xpf = ws_xml_get_xpath_value(doc, get_tests[i].fault_expr);
+ xpf = ws_xml_get_xpath_value(doc, get_tests[i].expr1);
CU_ASSERT_PTR_NOT_NULL(xpf);
if (!xpf) {
goto RETURN;
}
- CU_ASSERT_STRING_EQUAL(xpf, get_tests[i].fault_value);
+ CU_ASSERT_STRING_EQUAL(xpf, get_tests[i].value1);
- if (strcmp(xpf, get_tests[i].fault_value)) {
- //printf("Expected %s; returned %s\n",
- // get_tests[i].fault_value, xpf);
+ if (strcmp(xpf, get_tests[i].value1)) {
goto RETURN;
}
- if (get_tests[i].detail_expr == NULL) {
+ if (get_tests[i].expr2 == NULL) {
goto RETURN;
}
- xpd = ws_xml_get_xpath_value(doc, get_tests[i].detail_expr);
+ xpd = ws_xml_get_xpath_value(doc, get_tests[i].expr2);
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) {
+ CU_ASSERT_PTR_NOT_NULL(get_tests[i].value2);
+ if (get_tests[i].value2 == NULL) {
goto RETURN;
}
- CU_ASSERT_STRING_EQUAL(xpd, get_tests[i].detail_value );
- if (strcmp(xpd, get_tests[i].detail_value)) {
+ CU_ASSERT_STRING_EQUAL(xpd, get_tests[i].value2 );
+ if (strcmp(xpd, get_tests[i].value2)) {
goto RETURN;
}
diff --git a/tests/cunit/transfer_put.c b/tests/cunit/transfer_put.c
new file mode 100755
index 0000000..c9f39d9
--- /dev/null
+++ b/tests/cunit/transfer_put.c
@@ -0,0 +1,231 @@
+/*******************************************************************************
+ * 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 put_tests[] = {
+ {
+ "Transfer Put without any selectors.",
+ "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem",
+ 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
+ },
+
+ {
+ "Transfer Put with non existent Resource URI.",
+ "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystemxx",
+ 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
+ },
+
+ {
+ "Transfer Put with unsufficient selectors.",
+ "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem",
+ "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
+ },
+
+ {
+ "Transfer Put with wrong selectors.",
+ "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem",
+ "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
+ },
+
+ {
+ "Transfer Put with all selectors but with wrong values.",
+ "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ComputerSystem",
+ "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
+ },
+ {
+ "Transfer Put with correct selectors and parameters. Check response code",
+ "http://schema.omc-project.org/wbem/wscim/1/cim-schema/2/OMC_TimeZoneSettingData",
+ "InstanceID=omc:timezone",
+ "TimeZone=US/Pacific",
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ 200,
+ 0,
+ },
+};
+
+static int ntests = sizeof (put_tests) / sizeof (put_tests[0]);
+
+
+
+extern WsManClient *cl;
+actionOptions options;
+
+static void transfer_put_test() {
+ WsXmlDocH doc;
+ char *xpf = NULL;
+ char *xpd = NULL;
+ static int i = 0; // executed test number.
+ char *old_selectors = put_tests[i].selectors;
+
+
+ if (put_tests[i].selectors) {
+ put_tests[i].selectors =
+ u_strdup_printf(put_tests[i].selectors, host, host, host);
+ }
+
+ reinit_client_connection(cl);
+ initialize_action_options(&options);
+
+ if (put_tests[i].selectors != NULL) {
+ wsman_add_selectors_from_query_string (&options, put_tests[i].selectors);
+ }
+ if (put_tests[i].properties != NULL) {
+ wsman_add_properties_from_query_string (&options, put_tests[i].properties);
+ }
+
+
+ doc = ws_transfer_put(cl, (char *)put_tests[i].resource_uri, options);
+ CU_ASSERT_TRUE(wsman_get_client_response_code(cl) == put_tests[i].final_status);
+
+ CU_ASSERT_PTR_NOT_NULL(doc);
+ if (!doc) {
+ goto RETURN;
+ }
+ if (put_tests[i].expr1 == NULL) {
+ goto RETURN;
+ }
+ CU_ASSERT_PTR_NOT_NULL(put_tests[i].value1);
+ if (put_tests[i].value1 == NULL) {
+ goto RETURN;
+ }
+ xpf = ws_xml_get_xpath_value(doc, put_tests[i].expr1);
+ CU_ASSERT_PTR_NOT_NULL(xpf);
+ if (!xpf) {
+ goto RETURN;
+ }
+ CU_ASSERT_STRING_EQUAL(xpf, put_tests[i].value1);
+
+ if (strcmp(xpf, put_tests[i].value1)) {
+ //printf("Expected %s; returned %s\n",
+ // put_tests[i].value1, xpf);
+ goto RETURN;
+ }
+ if (put_tests[i].expr2 == NULL) {
+ goto RETURN;
+ }
+ xpd = ws_xml_get_xpath_value(doc, put_tests[i].expr2);
+ CU_ASSERT_PTR_NOT_NULL(xpd);
+ if (!xpd) {
+ goto RETURN;
+ }
+ CU_ASSERT_PTR_NOT_NULL(put_tests[i].value2);
+ if (put_tests[i].value2 == NULL) {
+ goto RETURN;
+ }
+ CU_ASSERT_STRING_EQUAL(xpd, put_tests[i].value2 );
+ if (strcmp(xpd, put_tests[i].value2)) {
+ goto RETURN;
+ }
+RETURN:
+ u_free(xpf);
+ u_free(xpd);
+ if (doc) {
+ ws_xml_destroy_doc(doc);
+ }
+ u_free((char *)put_tests[i].selectors);
+ put_tests[i].selectors = old_selectors;
+ destroy_action_options(&options);
+ i++; // increase executed test number
+}
+
+
+
+
+int add_transfer_put_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, put_tests[i].explanation,
+ (CU_TestFunc)transfer_put_test));
+ }
+ return (found_test > 0);
+}
+