(file) Return to test_wsbuf.cpp CVS log (file) (dir) Up to [OMI] / omi / tests / wsman

  1 krisbash 1.1 /*
  2              **==============================================================================
  3              **
  4              ** Open Management Infrastructure (OMI)
  5              **
  6              ** Copyright (c) Microsoft Corporation
  7              ** 
  8              ** Licensed under the Apache License, Version 2.0 (the "License"); you may not 
  9              ** use this file except in compliance with the License. You may obtain a copy 
 10              ** of the License at 
 11              **
 12              **     http://www.apache.org/licenses/LICENSE-2.0 
 13              **
 14              ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15              ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
 16              ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
 17              ** MERCHANTABLITY OR NON-INFRINGEMENT. 
 18              **
 19              ** See the Apache 2 License for the specific language governing permissions 
 20              ** and limitations under the License.
 21              **
 22 krisbash 1.1 **==============================================================================
 23              */
 24              
 25              #include <vector>
 26              #include <set>
 27              #include <cstdlib>
 28              #include <iostream>
 29              #include <ut/ut.h>
 30              #include <xml/xml.h>
 31              #include <wsman/wsbuf.h>
 32              
 33              using namespace std;
 34              
 35              #if defined(CONFIG_ENABLE_WCHAR)
 36              typedef std::wstring String;
 37              #else
 38              typedef std::string String;
 39              #endif
 40              
 41              WSBuf   s_buf;
 42              
 43 krisbash 1.1 NitsSetup(TestWsbufSetup)
 44              NitsEndSetup
 45              
 46              NitsCleanup(TestWsbufSetup)
 47              NitsEndCleanup
 48              
 49              #define TEST_STR_CHAR "`';\"\\!@#$%^&*()_+<>"
 50              #define TEST_STR MI_T("`';\"\\!@#$%^&*()_+<>")
 51              #define TEST_STR_ENCODED PAL_T("`&apos;;&quot;\\!@#$%^&amp;*()_+&lt;&gt;")
 52              
 53              #if defined(CONFIG_ENABLE_WCHAR)
 54              typedef std::wstring String;
 55              #else
 56              typedef std::string String;
 57              #endif
 58              
 59              NitsTestWithSetup(TestXMLStringEncoding, TestWsbufSetup)
 60              {
 61                  String result;    
 62                  
 63                  if(!TEST_ASSERT (MI_RESULT_OK == WSBuf_Init(&s_buf, 10)))
 64 krisbash 1.1         NitsReturn;
 65              
 66                  for ( unsigned int i = 0; i < 100; i++ )
 67                  {
 68                      result += TEST_STR_ENCODED;
 69                      TEST_ASSERT (MI_RESULT_OK == WSBuf_AddString(&s_buf, TEST_STR) );
 70                  }
 71              
 72                  Page* p = WSBuf_StealPage(&s_buf);
 73                  TEST_ASSERT(0 != p);
 74              
 75                  /* content expected to be 0-terminated */
 76                  String buf_result( (const ZChar*) (p + 1) );
 77                  //cout << buf_result << endl;
 78                  TEST_ASSERT(result == buf_result);
 79              
 80                  PAL_Free(p);
 81              
 82                  TEST_ASSERT (MI_RESULT_OK == WSBuf_Destroy(&s_buf));    
 83              }
 84              NitsEndTest
 85 krisbash 1.1 
 86              NitsTestWithSetup(TestToFromXML, TestWsbufSetup)
 87              {
 88                  String result;
 89                  Page* p = NULL;
 90                  XML * xml = NULL;
 91                  XML_Elem e;
 92                  if(!TEST_ASSERT (MI_RESULT_OK == WSBuf_Init(&s_buf, 10)))
 93                      NitsReturn;
 94              
 95                  if(!TEST_ASSERT (MI_RESULT_OK == WSBuf_AddStringNoEncoding(&s_buf, PAL_T("<a>")) ))
 96                      goto cleanup;
 97              
 98                  for ( unsigned int i = 0; i < 100; i++ )
 99                  {
100                      result += TEST_STR;
101                      if(!TEST_ASSERT (MI_RESULT_OK == WSBuf_AddString(&s_buf, TEST_STR) ))
102                          goto cleanup;
103                  }
104              
105                  if(!TEST_ASSERT (MI_RESULT_OK == WSBuf_AddStringNoEncoding(&s_buf, PAL_T("</a>")) ))
106 krisbash 1.1         goto cleanup;
107              
108                  p = WSBuf_StealPage(&s_buf);
109                  if(!TEST_ASSERT(0 != p))
110                      goto cleanup;
111              
112              
113                  /* create xml */
114                  xml = (XML *) PAL_Malloc(sizeof(XML));
115                  
116                  if(!TEST_ASSERT(xml != NULL))
117                      goto cleanup;
118                  XML_Init(xml);
119                  XML_SetText(xml, (ZChar*) (p + 1));
120              
121                  TEST_ASSERT(0 == XML_Next(xml, &e));
122                  TEST_ASSERT(Tcscmp(e.data.data, PAL_T("a")) == 0);
123                  TEST_ASSERT(e.type == XML_START);
124              
125                  TEST_ASSERT(0 == XML_Next(xml, &e));
126                  TEST_ASSERT(e.type == XML_CHARS);
127 krisbash 1.1     TEST_ASSERT(result == e.data.data);
128              
129                  TEST_ASSERT(0 == XML_Next(xml, &e));
130                  TEST_ASSERT(Tcscmp(e.data.data, PAL_T("a")) == 0);
131                  TEST_ASSERT(e.type == XML_END);
132              
133              cleanup:    
134                  if(p) PAL_Free(p);
135                  if(xml) PAL_Free(xml);
136              
137                  TEST_ASSERT (MI_RESULT_OK == WSBuf_Destroy(&s_buf));    
138              }
139              NitsEndTest
140              

ViewCVS 0.9.2