00001
00002
00003
00004 #include "ACEXML/common/XML_Util.h"
00005
00006 #include "ace/OS_main.h"
00007 #include "ace/Time_Value.h"
00008 #include "ace/OS_NS_sys_time.h"
00009 #include "ace/Log_Msg.h"
00010
00011 const int MAX_ITERATIONS = 100 * 1000;
00012 const int NUM_TEST_STRS = 6;
00013
00014 static bool is_escaped(const ACEXML_String& s)
00015 {
00016 if (s[0] != ACE_TEXT('&'))
00017 return false;
00018 if (s[s.length() - 1] != ACE_TEXT(';'))
00019 return false;
00020 return true;
00021 }
00022
00023 static int run_tests(ACEXML_String test_strings[NUM_TEST_STRS], int iterations)
00024 {
00025
00026 ACE_Time_Value start = ACE_OS::gettimeofday();
00027 int i = 0;
00028 for (i = 0; i < iterations; ++i)
00029 {
00030 ACEXML_String tmp = ACEXML_escape_string(test_strings[i % NUM_TEST_STRS]);
00031 if (! is_escaped(tmp))
00032 {
00033 ACE_ERROR((LM_ERROR, "Error: Failed to escape string\n"));
00034 return 1;
00035 }
00036 }
00037 ACE_DEBUG((LM_DEBUG, "Test1 took %dms\n", (ACE_OS::gettimeofday() - start).msec()));
00038
00039
00040
00041 ACEXML_String tmp;
00042 start = ACE_OS::gettimeofday();
00043 for (i = 0; i < iterations; ++i)
00044 {
00045 tmp = ACEXML_escape_string(test_strings[i % NUM_TEST_STRS]);
00046 if (! is_escaped(tmp))
00047 {
00048 ACE_ERROR((LM_ERROR, "Error: Failed to escape string\n"));
00049 return 1;
00050 }
00051 }
00052 ACE_DEBUG((LM_DEBUG, "Test2 took %dms\n", (ACE_OS::gettimeofday() - start).msec()));
00053
00054
00055
00056 tmp.clear(1);
00057 start = ACE_OS::gettimeofday();
00058 for (i = 0; i < iterations; ++i)
00059 {
00060 ACEXML_escape_string(test_strings[i % NUM_TEST_STRS], tmp);
00061 if (! is_escaped(tmp))
00062 {
00063 ACE_ERROR((LM_ERROR, "Error: Failed to escape string\n"));
00064 return 1;
00065 }
00066 }
00067 ACE_DEBUG((LM_DEBUG, "Test3 took %dms\n", (ACE_OS::gettimeofday() - start).msec()));
00068
00069
00070 start = ACE_OS::gettimeofday();
00071 for (i = 0; i < iterations; ++i)
00072 {
00073 ACEXML_escape_string(test_strings[i % NUM_TEST_STRS], tmp);
00074 if (! is_escaped(tmp))
00075 {
00076 ACE_ERROR((LM_ERROR, "Error: Failed to escape string\n"));
00077 return 1;
00078 }
00079 }
00080 ACE_DEBUG((LM_DEBUG, "Test4 took %dms\n", (ACE_OS::gettimeofday() - start).msec()));
00081 return 0;
00082 }
00083
00084 int ACE_TMAIN (int, ACE_TCHAR *[])
00085 {
00086 ACEXML_String test_strings[NUM_TEST_STRS] = {
00087 ACE_TEXT("\"xxxxx\"xxxxxxxx xx\"xxxxxx xxxxxx\"xxxxxxxxxx xxxxxxxx\"xxxxxx\""),
00088 ACE_TEXT("'xxxxx\'xxxxxxxx' xxxxxxxx xx'xxxxxxxx'xxxxxx xxxxxxx'xxxxxxx'"),
00089 ACE_TEXT("&xxxx&xxxxxxxxx &xxxxxxxx xxxxx&xxxxxxxxxxx xxxx&xxxxxxxxxx&"),
00090 ACE_TEXT(">xx>xxxxxxxxxxx >xxxxxxxx xxxxx>xxxxxxxxxxx xxxxx>xxxxxxxxx>"),
00091 ACE_TEXT("<xxxxx<xxxxxxxx xxxxxxxx <xxxxxxxxxxxxxxx<x xxxxxxxxxxxxxx<"),
00092 ACE_TEXT("&xxxx\"xxxxxxx&xx xxx'xxxxx xx<xxxxxxx>xxxxxxx xx\"xxxxxxxxxxxx>"),
00093 };
00094
00095 if (run_tests(test_strings, MAX_ITERATIONS) != 0)
00096 return 1;
00097
00098 ACE_DEBUG((LM_DEBUG, "Rerun tests with larger strings\n"));
00099 for (int i = 0; i < NUM_TEST_STRS; ++i)
00100 {
00101 for (int j = 0; j < 5; ++j)
00102 {
00103 test_strings[i] += test_strings[i];
00104 }
00105 }
00106
00107 if (run_tests(test_strings, MAX_ITERATIONS / 10) != 0)
00108 return 1;
00109
00110 return 0;
00111 }