diff options
author | kitty <kitty@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2002-10-20 03:28:08 +0000 |
---|---|---|
committer | kitty <kitty@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2002-10-20 03:28:08 +0000 |
commit | edb3741e619f916ff4c26b6f13b6b31aa64238f2 (patch) | |
tree | d3ee76aaea069cd3cf927b3dd25a9467fd4cf9c4 | |
parent | c303f878e5cd014d9b555573d77df6e66cbbce9d (diff) | |
download | ATCD-edb3741e619f916ff4c26b6f13b6b31aa64238f2.tar.gz |
ChangeLogTag: Sat Oct 19 20:00:00 2002 Stephen Torri <storri@cse.wustl.edu>
-rw-r--r-- | ChangeLog | 17 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-03a | 17 | ||||
-rw-r--r-- | ace/String_Base.i | 67 | ||||
-rw-r--r-- | tests/Recursive_Condition_Test.cpp | 222 | ||||
-rw-r--r-- | tests/SString_Test.cpp | 283 |
5 files changed, 379 insertions, 227 deletions
diff --git a/ChangeLog b/ChangeLog index 02ec85ca4d9..d66b2345b8a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +Sat Oct 19 20:00:00 2002 Stephen Torri <storri@cse.wustl.edu> + + * tests/Recursive_Condition_Test.cpp: + + Added test to check nesting_level after requiring a Recursive + Condition Mutex multiple times. Also after releasing for the + same number of times. + + * tests/SString_Test.cpp: + * ace/String_Base.i: + + Bug 1323: Fixed. In the effort to protect from memory problems + with non-null terminated strings the operators '<' and '>' where + rendered useless. Now the comparions use strcmp instead of + strncmp. A series of tests have been added to SString_Test.cpp + to ensure this does not happen again. + Sat Oct 19 21:58:00 2002 Krishnakumar B <kitty@cse.wustl.edu> * ace/Argv_Type_Converter.cpp: diff --git a/ChangeLogs/ChangeLog-03a b/ChangeLogs/ChangeLog-03a index 02ec85ca4d9..d66b2345b8a 100644 --- a/ChangeLogs/ChangeLog-03a +++ b/ChangeLogs/ChangeLog-03a @@ -1,3 +1,20 @@ +Sat Oct 19 20:00:00 2002 Stephen Torri <storri@cse.wustl.edu> + + * tests/Recursive_Condition_Test.cpp: + + Added test to check nesting_level after requiring a Recursive + Condition Mutex multiple times. Also after releasing for the + same number of times. + + * tests/SString_Test.cpp: + * ace/String_Base.i: + + Bug 1323: Fixed. In the effort to protect from memory problems + with non-null terminated strings the operators '<' and '>' where + rendered useless. Now the comparions use strcmp instead of + strncmp. A series of tests have been added to SString_Test.cpp + to ensure this does not happen again. + Sat Oct 19 21:58:00 2002 Krishnakumar B <kitty@cse.wustl.edu> * ace/Argv_Type_Converter.cpp: diff --git a/ace/String_Base.i b/ace/String_Base.i index 536c61fb42c..ca2817ac44e 100644 --- a/ace/String_Base.i +++ b/ace/String_Base.i @@ -35,7 +35,7 @@ ACE_String_Base<CHAR>::ACE_String_Base (const CHAR *s, length = ACE_OS::strlen (s); else length = 0; - + this->set (s, length, release); } @@ -209,29 +209,16 @@ ACE_String_Base<CHAR>::operator== (const ACE_String_Base<CHAR> &s) const { ACE_TRACE ("ACE_String_Base<CHAR>::operator=="); - return this->len_ == s.len_ - && ACE_OS::strncmp (this->rep_, s.rep_, this->len_) == 0; + return compare(s) == 0; } // Less than comparison operator. -template <class CHAR> ACE_INLINE int +template <class CHAR> ACE_INLINE int ACE_String_Base<CHAR>::operator < (const ACE_String_Base<CHAR> &s) const { ACE_TRACE ("ACE_String_Base<CHAR>::operator <"); - - size_t smaller_length = 0; - if (this->len_ < s.len_) - smaller_length = this->len_; - else - smaller_length = s.len_; - - if (this->rep_ && s.rep_) - return ACE_OS::strncmp (this->rep_, s.rep_, smaller_length) < 0; - else if (s.rep_) - return 1; - else - return 0; + return compare(s) < 0; } // Greater than comparison operator. @@ -240,19 +227,7 @@ template <class CHAR> ACE_INLINE int ACE_String_Base<CHAR>::operator > (const ACE_String_Base &s) const { ACE_TRACE ("ACE_String_Base<CHAR>::operator >"); - size_t smaller_length = 0; - - if (this->len_ < s.len_) - smaller_length = this->len_; - else - smaller_length = s.len_; - - if (this->rep_ && s.rep_) - return ACE_OS::strncmp (this->rep_, s.rep_, smaller_length) > 0; - else if (this->rep_) - return 1; - else - return 0; + return compare(s) > 0; } @@ -270,28 +245,18 @@ ACE_String_Base<CHAR>::compare (const ACE_String_Base<CHAR> &s) const { ACE_TRACE ("ACE_String_Base<CHAR>::compare"); - // We can't just pass both strings to strncmp, since they are not - // guaranteed to be null-terminated. - // Pick smaller of the two lengths and perform the comparison. - size_t smaller_length = 0; - - if (this->len_ < s.len_) - smaller_length = this->len_; - else - smaller_length = s.len_; - - int result = ACE_OS::strncmp (this->rep_, - s.rep_, - smaller_length); - - if (result != 0 || s.len_ == this->len_) - return result; - else if (this->len_ > s.len_) - // we need to differentiate based on length - return (this->rep_[smaller_length] - '\0'); - else - return ('\0' - s.rep_[smaller_length]); + size_t smaller_length = ace_min(this->len_,s.len_); + + int result = ACE_OS::memcmp (this->rep_, + s.rep_, + smaller_length); + + if (!result) + { + result = this->len_ - s.len_; + } + return result; } template <class CHAR> ACE_INLINE ssize_t diff --git a/tests/Recursive_Condition_Test.cpp b/tests/Recursive_Condition_Test.cpp index d8885344cf5..4fc013f7b9b 100644 --- a/tests/Recursive_Condition_Test.cpp +++ b/tests/Recursive_Condition_Test.cpp @@ -23,16 +23,16 @@ #include "test_config.h" #include "ace/Event_Handler.h" #include "ace/Synch.h" +#include "ace/Trace.h" #include "ace/Thread_Manager.h" #include "ace/Timer_Heap.h" #include "ace/Timer_Queue_Adapters.h" ACE_RCSID(tests, Recursive_Condition_Test, "$Id$") - + #if defined (ACE_HAS_THREADS) - -typedef ACE_Thread_Timer_Queue_Adapter<ACE_Timer_Heap> - Thread_Timer_Queue; + + typedef ACE_Thread_Timer_Queue_Adapter<ACE_Timer_Heap> Thread_Timer_Queue; class Test_Handler : public ACE_Event_Handler { @@ -40,18 +40,18 @@ public: virtual int handle_timeout (const ACE_Time_Value &, const void *arg) { - ACE_DEBUG ((LM_DEBUG, "[%t] handle_timeout\n")); - + ACE_TRACE ("[%t] handle_timeout\n"); + Thread_Timer_Queue *timer_queue = (Thread_Timer_Queue *) arg; - + ACE_Time_Value timeout = ACE_OS::gettimeofday () + ACE_Time_Value (1, 0); - ACE_DEBUG ((LM_DEBUG, "[%t] scheduling timer\n")); - - int timer_id = + ACE_TRACE ("[%t] scheduling timer\n"); + + /* + int timer_id = timer_queue->schedule (this, timer_queue, timeout); - ACE_DEBUG ((LM_DEBUG, "[%t] timer id = %d\n", timer_id)); - + */ return 0; } }; @@ -62,9 +62,9 @@ ACE_SYNCH_RECURSIVE_CONDITION condition_(mutex_); ACE_THR_FUNC_RETURN waiter (void *) { ACE_ASSERT (mutex_.acquire () == 0); - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) waiting for cv signal...\n"))); + ACE_TRACE (ACE_TEXT ("(%t) waiting for cv signal...\n")); condition_.wait(); - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) woken up!!!\n"))); + ACE_TRACE (ACE_TEXT ("(%t) woken up!!!\n")); mutex_.release (); return 0; } @@ -72,77 +72,181 @@ ACE_THR_FUNC_RETURN waiter (void *) { #endif /* ACE_HAS_THREADS */ int -ACE_TMAIN (int, ACE_TCHAR *[]) +test_1(void) { - ACE_START_TEST (ACE_TEXT ("Recursive_Condition_Test")); - -#if defined (ACE_HAS_THREADS) - Thread_Timer_Queue timer_queue; - Test_Handler handler; - int status = timer_queue.activate (); - - ACE_ASSERT (status == 0); - - ACE_Time_Value timeout = - ACE_OS::gettimeofday() + ACE_Time_Value (1, 0); - - ACE_DEBUG ((LM_DEBUG, "[%t] scheduling timer\n")); - - int timer_id = timer_queue.schedule (&handler, &timer_queue, timeout); - ACE_DEBUG ((LM_DEBUG, "[%t] timer id = %d\n", timer_id)); - - ACE_OS::sleep (10); - timer_queue.deactivate (); - timer_queue.wait (); - - // Now do a simple wait/signal combination across two threads. if (ACE_Thread_Manager::instance()->spawn (waiter) == -1) - ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("spawn")), 1); - + { + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("spawn")), 1); + } + ACE_OS::sleep (2); if (mutex_.acquire () == -1) - ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), - ACE_TEXT ("mutex acquire")), - 1); - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) signaling condition...\n"))); + { + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), + ACE_TEXT ("mutex acquire")), + 1); + } + ACE_TRACE (ACE_TEXT ("(%t) signaling condition...\n")); + if (condition_.signal () == -1) - ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("signal"))); + { + ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("signal"))); + } + mutex_.release (); ACE_Thread_Manager::instance ()->wait (); + return 0; +} - // Test #2 - Sleep 2 seconds before releasing mutex +int +test_2(void) +{ if (ACE_Thread_Manager::instance()->spawn (waiter) == -1) - ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("spawn")), 1); - + { + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("spawn")), 1); + } + ACE_OS::sleep (2); if (mutex_.acquire () == -1) - ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), - ACE_TEXT ("mutex acquire")), - 1); + { + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), + ACE_TEXT ("mutex acquire")), + 1); + } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) signaling condition...\n"))); + if (condition_.signal () == -1) - { - ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("signal"))); - } + { + ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("signal"))); + } + ACE_OS::sleep(2); mutex_.release (); ACE_Thread_Manager::instance ()->wait (); + return 0; +} - // Test #3 - One main thread - 4 subthreads +int +test_3() +{ if (ACE_Thread_Manager::instance()->spawn_n (4,waiter) == -1) - ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("spawn")), 1); - + { + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("spawn")), 1); + } + ACE_OS::sleep (2); if (mutex_.acquire () == -1) - ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), - ACE_TEXT ("mutex acquire")), + { + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), + ACE_TEXT ("mutex acquire")), 1); + } ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) signaling condition...\n"))); + if (condition_.broadcast () == -1) - ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("signal"))); + { + ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("signal"))); + } mutex_.release (); ACE_Thread_Manager::instance ()->wait (); + + return 0; +} + +int +test_4() +{ + if (ACE_Thread_Manager::instance()->spawn (waiter) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("spawn")), 1); + } + + ACE_OS::sleep (2); + for(int i = 0; i < 3; ++i){ + if (mutex_.acquire () == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), + ACE_TEXT ("mutex acquire")), + 1); + } + } + + if (mutex_.get_nesting_level() != 3) + { + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("%d\n"), + ACE_TEXT("get_nestling_level")), + 1); + } + + ACE_TRACE (ACE_TEXT ("(%t) signaling condition...\n")); + if (condition_.signal () == -1) + { + ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("signal"))); + } + + for(int i = 0; i < 3; ++i){ + mutex_.release (); + } + + if (mutex_.get_nesting_level() != 0) + { + ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("%d\n"), + ACE_TEXT("get_nestling_level")), + 1); + } + ACE_Thread_Manager::instance ()->wait (); + return 0; +} + +int +ACE_TMAIN (int, ACE_TCHAR *[]) +{ + ACE_START_TEST (ACE_TEXT ("Recursive_Condition_Test")); + +#if defined (ACE_HAS_THREADS) +#if 0 + Thread_Timer_Queue timer_queue; + Test_Handler handler; + int status = timer_queue.activate (); + + ACE_ASSERT (status == 0); + + ACE_Time_Value timeout = + ACE_OS::gettimeofday() + ACE_Time_Value (1, 0); + + ACE_TRACE ("[%t] scheduling timer\n"); + + int timer_id = timer_queue.schedule (&handler, &timer_queue, timeout); + + ACE_OS::sleep (10); + timer_queue.deactivate (); + timer_queue.wait (); +#endif + + /* Test 1 - Simple test */ + if (test_1 () != 0) + { + ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT("test #1")), 1); + } + + /* Test #2 - Sleep 2 seconds before releasing mutex */ + if (test_2 () != 0) + { + ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT("test #2")), 1); + } + + /* Test #3 - One main thread - 4 subthreads */ + if (test_3 () != 0) + { + ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT("test #3")), 1); + } + /* Test #4 - Multiple calls to mutex_.acquire and mutex_.release */ + if (test_4 () != 0) + { + ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT("test #4")), 1); + } + #else ACE_ERROR ((LM_ERROR, ACE_TEXT ("ACE doesn't support recursive condition variables on this platform\n"))); diff --git a/tests/SString_Test.cpp b/tests/SString_Test.cpp index 68a1ad9479d..6a2d29b340c 100644 --- a/tests/SString_Test.cpp +++ b/tests/SString_Test.cpp @@ -24,12 +24,14 @@ ACE_RCSID(tests, SString_Test, "$Id$") -int + int ACE_TMAIN (int, ACE_TCHAR *[]) { ACE_START_TEST (ACE_TEXT ("SString_Test")); { + + /* Set #1 */ ACE_CString s0 ("hello"); ACE_CString s1 ("hello"); ACE_CString s2 ("world"); @@ -43,50 +45,51 @@ ACE_TMAIN (int, ACE_TCHAR *[]) ACE_CString empty_string; ACE_CString zero_size_string (s1.c_str (), 0, 0, 1); - // Not equal comparisons. - ACE_ASSERT (s1 != s2); - ACE_ASSERT (s1 != s5); - - // Equal comparisons. - ACE_ASSERT (s1 == s1); - ACE_ASSERT (s1 == s0); - - // Substring match. - ACE_ASSERT (s1.strstr (s2) == -1); - ACE_ASSERT (s1.strstr (s3) == 2); - ACE_ASSERT (s3.strstr (s1) == -1); - ACE_ASSERT (s1.strstr (s4) == 1); - - // Substring creation. - ACE_ASSERT (s1.substring (0) == s1); - ACE_ASSERT (s1.substring (1) == s4); - ACE_ASSERT (s1.substring (2, 2) == s3); - ACE_ASSERT (s1.substring (0, 0) == empty_string); - ACE_ASSERT (s1.substring (4, 10).length () == 1); - - // Forward search. - ACE_ASSERT (s1.find (s3) == 2); - ACE_ASSERT (s3.find (s1) == ACE_CString::npos); - ACE_ASSERT (s1.find (s3, 2) == 2); - ACE_ASSERT (s3.find (s1, 1) == ACE_CString::npos); - ACE_ASSERT (s1.find (s2) == ACE_CString::npos); - ACE_ASSERT (s1.find ('o') == 4); - - // Reverse search. - ACE_ASSERT (s1.rfind ('l') == 3); - ACE_ASSERT (s1.rfind ('l', 3) == 2); - - // Assignment. + // Not equal comparisons. Error if they are equal + if (s1 == s2){ACE_ERROR((LM_ERROR,"Set #1:\n"));} + if (s1 == s5){ACE_ERROR((LM_ERROR,"Set #1: \n"));} + + // Equal comparisons. Error if they are not equal + if (s1 != s1){ACE_ERROR((LM_ERROR,"Set #1: \n"));} + if (s1 != s0){ACE_ERROR((LM_ERROR,"Set #1: \n"));} + + // Substring match. Error if they are not equal + if (s1.strstr (s2) != -1){ACE_ERROR((LM_ERROR,"Set #1: \n"));} + if (s1.strstr (s3) != 2){ACE_ERROR((LM_ERROR,"Set #1: \n"));} + if (s3.strstr (s1) != -1){ACE_ERROR((LM_ERROR,"Set #1: \n"));} + if (s1.strstr (s4) != 1){ACE_ERROR((LM_ERROR,"Set #1: \n"));} + + // Substring creation. Error if they are not equal + if (s1.substring (0) != s1){ACE_ERROR((LM_ERROR,"Set #1: \n"));} + if (s1.substring (1) != s4){ACE_ERROR((LM_ERROR,"Set #1: \n"));} + if (s1.substring (2, 2) != s3){ACE_ERROR((LM_ERROR,"Set #1: \n"));} + if (s1.substring (0, 0) != empty_string){ACE_ERROR((LM_ERROR,"Set #1: \n"));} + if (s1.substring (4, 10).length () != 1){ACE_ERROR((LM_ERROR,"Set #1: \n"));} + + // Forward search. Error if they are not equal + if (s1.find (s3) != 2){ACE_ERROR((LM_ERROR,"Set #1: \n"));} + if (s3.find (s1) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #1: \n"));} + if (s1.find (s3, 2) != 2){ACE_ERROR((LM_ERROR,"Set #1: \n"));} + if (s3.find (s1, 1) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #1: \n"));} + if (s1.find (s2) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #1: \n"));} + if (s1.find ('o') != 4){ACE_ERROR((LM_ERROR,"Set #1: \n"));} + + // Reverse search. Error if they are not equal + if (s1.rfind ('l') != 3){ACE_ERROR((LM_ERROR,"Set #1: \n"));} + if (s1.rfind ('l', 3) != 2){ACE_ERROR((LM_ERROR,"Set #1: \n"));} + + // Assignment. Error if they are not equal ACE_CString s6; s6 = s0; - ACE_ASSERT (s6 == s0); + if (s6 != s0){ACE_ERROR((LM_ERROR,"Set #1: \n"));} s6 = s4; - ACE_ASSERT (s4 == s6); + if (s4 != s6){ACE_ERROR((LM_ERROR,"Set #1: \n"));} s6 = s5; - ACE_ASSERT (s6 == s5); + if (s6 != s5){ACE_ERROR((LM_ERROR,"Set #1: \n"));} } { + /* Set #2 */ ACE_CString s0 ("hello", 0, 0); ACE_CString s1 ("hello", 0, 0); ACE_CString s2 ("world", 0, 0); @@ -100,60 +103,61 @@ ACE_TMAIN (int, ACE_TCHAR *[]) ACE_CString empty_string (0, 0, 0); ACE_CString zero_size_string (s1.c_str (), 0, 0, 0); - // Not equal comparisons. - ACE_ASSERT (s1 != s2); - ACE_ASSERT (s1 != s5); - - // Equal comparisons. - ACE_ASSERT (s1 == s1); - ACE_ASSERT (s1 == s0); - - // Substring match. - ACE_ASSERT (s1.strstr (s2) == -1); - ACE_ASSERT (s1.strstr (s3) == 2); - ACE_ASSERT (s3.strstr (s1) == -1); - ACE_ASSERT (s1.strstr (s4) == 1); - - // Substring creation. - ACE_ASSERT (s1.substring (0) == s1); - ACE_ASSERT (s1.substring (1) == s4); - ACE_ASSERT (s1.substring (2, 2) == s3); - ACE_ASSERT (s1.substring (0, 0) == empty_string); - - // Forward search. - ACE_ASSERT (s1.find (s3) == 2); - ACE_ASSERT (s3.find (s1) == ACE_CString::npos); - ACE_ASSERT (s1.find (s3, 2) == 2); - ACE_ASSERT (s3.find (s1, 1) == ACE_CString::npos); - ACE_ASSERT (s1.find (s2) == ACE_CString::npos); - ACE_ASSERT (s1.find ('o') == 4); - - // Reverse search. - ACE_ASSERT (s1.rfind ('l') == 3); - ACE_ASSERT (s1.rfind ('l', 3) == 2); - - // Assignment. + // Not equal comparisons. Error if they are equal + if (s1 == s2){ACE_ERROR((LM_ERROR,"Set #2: \n"));} + if (s1 == s5){ACE_ERROR((LM_ERROR,"Set #2: \n"));} + + // Equal comparisons. Error if they are not equal + if (s1 != s1){ACE_ERROR((LM_ERROR,"Set #2: \n"));} + if (s1 != s0){ACE_ERROR((LM_ERROR,"Set #2: \n"));} + + // Substring match. Error if they are not equal + if (s1.strstr (s2) != -1){ACE_ERROR((LM_ERROR,"Set #2: \n"));} + if (s1.strstr (s3) != 2){ACE_ERROR((LM_ERROR,"Set #2: \n"));} + if (s3.strstr (s1) != -1){ACE_ERROR((LM_ERROR,"Set #2: \n"));} + if (s1.strstr (s4) != 1){ACE_ERROR((LM_ERROR,"Set #2: \n"));} + + // Substring creation. Error if they are not equal + if (s1.substring (0) != s1){ACE_ERROR((LM_ERROR,"Set #2: \n"));} + if (s1.substring (1) != s4){ACE_ERROR((LM_ERROR,"Set #2: \n"));} + if (s1.substring (2, 2) != s3){ACE_ERROR((LM_ERROR,"Set #2: \n"));} + if (s1.substring (0, 0) != empty_string){ACE_ERROR((LM_ERROR,"Set #2: \n"));} + + // Forward search. Error if they are not equal + if (s1.find (s3) != 2){ACE_ERROR((LM_ERROR,"Set #2: \n"));} + if (s3.find (s1) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #2: \n"));} + if (s1.find (s3, 2) != 2){ACE_ERROR((LM_ERROR,"Set #2: \n"));} + if (s3.find (s1, 1) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #2: \n"));} + if (s1.find (s2) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #2: \n"));} + if (s1.find ('o') != 4){ACE_ERROR((LM_ERROR,"Set #2: \n"));} + + // Reverse search. Error if they are not equal + if (s1.rfind ('l') != 3){ACE_ERROR((LM_ERROR,"Set #2: \n"));} + if (s1.rfind ('l', 3) != 2){ACE_ERROR((LM_ERROR,"Set #2: \n"));} + + // Assignment. Error if they are not equal ACE_CString s6; s6 = s0; - ACE_ASSERT (s6 == s0); + if (s6 != s0){ACE_ERROR((LM_ERROR,"Set #2: \n"));} s6 = s4; - ACE_ASSERT (s4 == s6); + if (s4 != s6){ACE_ERROR((LM_ERROR,"Set #2: \n"));} s6 = s5; - ACE_ASSERT (s6 == s5); + if (s6 != s5){ACE_ERROR((LM_ERROR,"Set #2: \n"));} - // Clear + // Clear. Error if they are not equal s0.clear(); - ACE_ASSERT (s0.length() == 0); + if (s0.length() != 0){ACE_ERROR((LM_ERROR,"Set #2: \n"));} - // Rep + // Rep. Error if they are not equal ACE_Auto_Basic_Array_Ptr<char> s (s1.rep ()); - ACE_ASSERT (ACE_OS::strlen (s.get ()) == s1.length ()); + if (ACE_OS::strlen (s.get ()) != s1.length ()); ACE_CString s7 (s.get ()); - ACE_ASSERT (s1 == s7); + if (s1 != s7){ACE_ERROR((LM_ERROR,"Set #2: \n"));} } { + /* Set #3 */ ACE_NS_WString s0 ("hello"); ACE_NS_WString s1 ("hello"); ACE_NS_WString s2 ("world"); @@ -167,52 +171,97 @@ ACE_TMAIN (int, ACE_TCHAR *[]) ACE_NS_WString empty_string; ACE_NS_WString zero_size_string (s1.c_str (), 0, 0); - // Not equal comparisons. - ACE_ASSERT (s1 != s2); - ACE_ASSERT (s1 != s5); - - // Equal comparisons. - ACE_ASSERT (s1 == s1); - ACE_ASSERT (s1 == s0); - - // Substring match. - ACE_ASSERT (s1.strstr (s2) == -1); - ACE_ASSERT (s1.strstr (s3) == 2); - ACE_ASSERT (s3.strstr (s1) == -1); - ACE_ASSERT (s1.strstr (s4) == 1); - - // Substring creation. - ACE_ASSERT (s1.substring (0) == s1); - ACE_ASSERT (s1.substring (1) == s4); - ACE_ASSERT (s1.substring (2, 2) == s3); - ACE_ASSERT (s1.substring (0, 0) == empty_string); - - // Forward search. - ACE_ASSERT (s1.find (s3) == 2); - ACE_ASSERT (s3.find (s1) == ACE_WString::npos); - ACE_ASSERT (s1.find (s3, 2) == 2); - ACE_ASSERT (s3.find (s1, 1) == ACE_WString::npos); - ACE_ASSERT (s1.find (s2) == ACE_WString::npos); - ACE_ASSERT (s1.find ('o') == 4); - - // Reverse search. - ACE_ASSERT (s1.rfind ('l') == 3); - ACE_ASSERT (s1.rfind ('l', 3) == 2); - - // Assignment. + // Not equal comparisons. Error if they are equal + if (s1 == s2){ACE_ERROR((LM_ERROR,"Set #3: \n"));} + if (s1 == s5){ACE_ERROR((LM_ERROR,"Set #3: \n"));} + + // Equal comparisons. Error if they are not equal + if (s1 != s1){ACE_ERROR((LM_ERROR,"Set #3: \n"));} + if (s1 != s0){ACE_ERROR((LM_ERROR,"Set #3: \n"));} + + // Substring match. Error if they are not equal + if (s1.strstr (s2) != -1){ACE_ERROR((LM_ERROR,"Set #3: \n"));} + if (s1.strstr (s3) != 2){ACE_ERROR((LM_ERROR,"Set #3: \n"));} + if (s3.strstr (s1) != -1){ACE_ERROR((LM_ERROR,"Set #3: \n"));} + if (s1.strstr (s4) != 1){ACE_ERROR((LM_ERROR,"Set #3: \n"));} + + // Substring creation. Error if they are not equal + if (s1.substring (0) != s1){ACE_ERROR((LM_ERROR,"Set #3: \n"));} + if (s1.substring (1) != s4){ACE_ERROR((LM_ERROR,"Set #3: \n"));} + if (s1.substring (2, 2) != s3){ACE_ERROR((LM_ERROR,"Set #3: \n"));} + if (s1.substring (0, 0) != empty_string){ACE_ERROR((LM_ERROR,"Set #3: \n"));} + + // Forward search. Error if they are not equal + if (s1.find (s3) != 2){ACE_ERROR((LM_ERROR,"Set #3: \n"));} + if (s3.find (s1) != ACE_WString::npos){ACE_ERROR((LM_ERROR,"Set #3: \n"));} + if (s1.find (s3, 2) != 2){ACE_ERROR((LM_ERROR,"Set #3: \n"));} + if (s3.find (s1, 1) != ACE_WString::npos){ACE_ERROR((LM_ERROR,"Set #3: \n"));} + if (s1.find (s2) != ACE_WString::npos){ACE_ERROR((LM_ERROR,"Set #3: \n"));} + if (s1.find ('o') != 4){ACE_ERROR((LM_ERROR,"Set #3: \n"));} + + // Reverse search. Error if they are not equal + if (s1.rfind ('l') != 3){ACE_ERROR((LM_ERROR,"Set #3: \n"));} + if (s1.rfind ('l', 3) != 2){ACE_ERROR((LM_ERROR,"Set #3: \n"));} + + // Assignment. Error if they are not equal ACE_NS_WString s6; s6 = s0; - ACE_ASSERT (s6 == s0); + if (s6 != s0){ACE_ERROR((LM_ERROR,"Set #3: \n"));} s6 = s4; - ACE_ASSERT (s4 == s6); + if (s4 != s6){ACE_ERROR((LM_ERROR,"Set #3: \n"));} s6 = s5; - ACE_ASSERT (s6 == s5); + if (s6 != s5){ACE_ERROR((LM_ERROR,"Set #3: \n"));} - // Clear + // Clear. Error if they are not equal s0.clear(); - ACE_ASSERT (s0.length() == 0); + if (s0.length() != 0){ACE_ERROR((LM_ERROR,"Set #3: \n"));} } + { + /* Set #4 */ + ACE_CString s1("dog"); + ACE_CString s2("d"); + + if (s1 == s2){ACE_ERROR((LM_ERROR,"Set #4: \n"));} + if (!(s1 > s2)){ACE_ERROR((LM_ERROR,"Set #4: \n"));} + if (s1 < s2){ACE_ERROR((LM_ERROR,"Set #4: \n"));} + + ACE_CString s3 ("dog"); + ACE_CString s4 ("dogbert"); + + if (s3 == s4){ACE_ERROR((LM_ERROR,"Set #4: \n"));} + if (!(s3 < s4)){ACE_ERROR((LM_ERROR,"Set #4: \n"));} + if (s3 > s4){ACE_ERROR((LM_ERROR,"Set #4: \n"));} + + ACE_CString s5 ("dogbert",3); + ACE_CString s6 ("dogbert",5); + + if(s5 == s6){ACE_ERROR((LM_ERROR,"Set #4: \n"));} + if(!(s5 < s6)){ACE_ERROR((LM_ERROR,"Set #4: \n"));} + if(s5 > s6){ACE_ERROR((LM_ERROR,"Set #4: \n"));} + + ACE_CString s7 ("dogbert",4); + ACE_CString s8 ("dogbert",2); + + if(s7 == s8){ACE_ERROR((LM_ERROR,"Set #4: \n"));} + if(!(s7 > s8)){ACE_ERROR((LM_ERROR,"Set #4: \n"));} + if(s7 < s8){ACE_ERROR((LM_ERROR,"Set #4: \n"));} + + ACE_CString s9 ("dogbert",3); + ACE_CString s10 ("dogbert"); + + if(s9 == s10){ACE_ERROR((LM_ERROR,"Set #4: \n"));} + if(!(s9 < s10)){ACE_ERROR((LM_ERROR,"Set #4: \n"));} + if(s9 > s10){ACE_ERROR((LM_ERROR,"Set #4: \n"));} + + ACE_CString s11 ("dogbert",5); + ACE_CString s12 ("dog"); + + if(s11 == s12){ACE_ERROR((LM_ERROR,"Set #4: \n"));} + if(!(s11 > s12)){ACE_ERROR((LM_ERROR,"Set #4: \n"));} + if(s11 < s12){ACE_ERROR((LM_ERROR,"Set #4: \n"));} + + } ACE_END_TEST; return 0; } |