![]() ![]() |
![]() |
File: [OMI] / omi / wsman / tests / Attic / test_wsbuf.cpp
(download)
Revision: 1.1, Mon Jun 25 18:54:42 2012 UTC (12 years ago) by mike Branch: MAIN CVS Tags: OMI_1_0_2, OMI_1_0_0 1.0.2 |
/* **============================================================================== ** ** 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 <vector> #include <set> #include <cstdlib> #include <iostream> #include <xml/xml.h> #include <wsman/wsbuf.h> #include <ut/ut.h> using namespace std; WSBuf s_buf; static void setUp() { UT_ASSERT (MI_RESULT_OK == WSBuf_Init(&s_buf, 10)); } static void cleanup() { UT_ASSERT (MI_RESULT_OK == WSBuf_Destroy(&s_buf)); } #define TEST_STR_CHAR "`';\"\\!@#$%^&*()_+<>" #define TEST_STR MI_T("`';\"\\!@#$%^&*()_+<>") #define TEST_STR_ENCODED "`';"\\!@#$%^&*()_+<>" static void TestXMLStringEncoding() { string result; for ( unsigned int i = 0; i < 100; i++ ) { result += TEST_STR_ENCODED; UT_ASSERT (MI_RESULT_OK == WSBuf_AddString(&s_buf, TEST_STR) ); } Page* p = WSBuf_StealPage(&s_buf); UT_ASSERT(0 != p); /* content expected to be 0-terminated */ string buf_result( (const char*) (p + 1) ); //cout << buf_result << endl; UT_ASSERT(result == buf_result); free(p); } static void TestToFromXML() { string result; UT_ASSERT (MI_RESULT_OK == WSBuf_AddStringNoEncoding(&s_buf, MI_T("<a>")) ); for ( unsigned int i = 0; i < 100; i++ ) { result += TEST_STR_CHAR; UT_ASSERT (MI_RESULT_OK == WSBuf_AddString(&s_buf, TEST_STR) ); } UT_ASSERT (MI_RESULT_OK == WSBuf_AddStringNoEncoding(&s_buf, MI_T("</a>")) ); Page* p = WSBuf_StealPage(&s_buf); UT_ASSERT(0 != p); /* create xml */ XML xml; XML_Elem e; XML_Init(&xml); XML_SetText(&xml, (char*) (p + 1)); UT_ASSERT(0 == XML_Next(&xml, &e)); UT_ASSERT(strcmp(e.data, "a") == 0); UT_ASSERT(e.type == XML_START); UT_ASSERT(0 == XML_Next(&xml, &e)); UT_ASSERT(e.type == XML_CHARS); UT_ASSERT(result == e.data); UT_ASSERT(0 == XML_Next(&xml, &e)); UT_ASSERT(strcmp(e.data, "a") == 0); UT_ASSERT(e.type == XML_END); free(p); } static void AllProviderTests() { // general errors UT_TEST(TestXMLStringEncoding); UT_TEST(TestToFromXML); } UT_ENTRY_POINT(AllProviderTests);
ViewCVS 0.9.2 |