summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichel_j <michel_j@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2005-05-23 18:10:38 +0000
committermichel_j <michel_j@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2005-05-23 18:10:38 +0000
commit3faf4be34859ecb3e7e83ee357760caba0696511 (patch)
treeee7809b50251dc9f463337e695767abdfa023118
parent46cffda57a5a0a26594b2eb3a5b3a565c094846f (diff)
downloadATCD-3faf4be34859ecb3e7e83ee357760caba0696511.tar.gz
ChangeLogTag: Mon May 23 13:02:25 2005 Justin Michel <michel_j@ociweb.com>
-rw-r--r--ACEXML/common/XML_Util.cpp46
-rw-r--r--ACEXML/common/XML_Util.h32
-rw-r--r--ACEXML/tests/util/test.cpp110
-rw-r--r--ACEXML/tests/util/util.mpc3
-rw-r--r--ChangeLog34
-rw-r--r--ace/String_Base.cpp128
-rw-r--r--ace/String_Base.h122
-rw-r--r--ace/String_Base.inl79
-rw-r--r--bin/tao_other_tests.lst14
-rw-r--r--tests/SString_Test.cpp235
10 files changed, 587 insertions, 216 deletions
diff --git a/ACEXML/common/XML_Util.cpp b/ACEXML/common/XML_Util.cpp
new file mode 100644
index 00000000000..7b9b9fb00fe
--- /dev/null
+++ b/ACEXML/common/XML_Util.cpp
@@ -0,0 +1,46 @@
+// $Id$
+
+#include "ACEXML/common/XML_Util.h"
+
+static const ACEXML_Char ESCAPED_AMP[] = ACE_TEXT("&amp;");
+static const ACEXML_Char ESCAPED_LESS[] = ACE_TEXT("&lt;");
+static const ACEXML_Char ESCAPED_GREATER[] = ACE_TEXT("&gt;");
+static const ACEXML_Char ESCAPED_APOS[] = ACE_TEXT("&apos;");
+static const ACEXML_Char ESCAPED_QUOTE[] = ACE_TEXT("&quot;");
+
+#define CSTRLEN(x) ((sizeof(x) / sizeof(ACEXML_Char)) - 1)
+
+ACEXML_String ACEXML_escape_string(const ACEXML_String& str)
+{
+ ACEXML_String ret(str.length ());
+ ACEXML_escape_string(str, ret);
+ return ret;
+}
+
+void ACEXML_escape_string(const ACEXML_String& in, ACEXML_String& out)
+{
+ size_t len = in.length ();
+ out.clear();
+ for (size_t stridx = 0; stridx < len; ++stridx)
+ {
+ switch (in[stridx]) {
+ case '&':
+ out.append(ESCAPED_AMP, CSTRLEN(ESCAPED_AMP));
+ break;
+ case '<':
+ out.append(ESCAPED_LESS, CSTRLEN(ESCAPED_LESS));
+ break;
+ case '>':
+ out.append(ESCAPED_GREATER, CSTRLEN(ESCAPED_GREATER));
+ break;
+ case '\'':
+ out.append(ESCAPED_APOS, CSTRLEN(ESCAPED_APOS));
+ break;
+ case '\"':
+ out.append(ESCAPED_QUOTE, CSTRLEN(ESCAPED_QUOTE));
+ break;
+ default:
+ out += in[stridx];
+ }
+ }
+}
diff --git a/ACEXML/common/XML_Util.h b/ACEXML/common/XML_Util.h
new file mode 100644
index 00000000000..a22b568ddd5
--- /dev/null
+++ b/ACEXML/common/XML_Util.h
@@ -0,0 +1,32 @@
+// -*- C++ -*-
+
+//=============================================================================
+/**
+ * @file XML_Util.h
+ *
+ * Initially contains a function to escape strings for use in XML files.
+ *
+ * $Id$
+ *
+ * @author Justin Michel <michel_j@ociweb.com>
+ */
+//=============================================================================
+
+#ifndef _ACEXML_XML_UTIL_H_
+#define _ACEXML_XML_UTIL_H_
+
+#include /**/ "ace/pre.h"
+
+#if !defined (ACE_LACKS_PRAGMA_ONCE)
+#pragma once
+#endif /* ACE_LACKS_PRAGMA_ONCE */
+
+#include "ACEXML/common/ACEXML_Export.h"
+#include "ACEXML/common/XML_Types.h"
+
+ACEXML_Export ACEXML_String ACEXML_escape_string(const ACEXML_String& str);
+ACEXML_Export void ACEXML_escape_string(const ACEXML_String& in, ACEXML_String& out);
+
+#include /**/ "ace/post.h"
+
+#endif /* _ACEXML_XML_UTIL_H_ */
diff --git a/ACEXML/tests/util/test.cpp b/ACEXML/tests/util/test.cpp
new file mode 100644
index 00000000000..8ed59accc59
--- /dev/null
+++ b/ACEXML/tests/util/test.cpp
@@ -0,0 +1,110 @@
+// $Id$
+// A simple test for performance of the ACEXML_escape_string() function
+
+#include "ACEXML/common/XML_Util.h"
+
+#include "ace/OS_main.h"
+#include "ace/Time_Value.h"
+#include "ace/OS_NS_sys_time.h"
+#include "ace/Log_Msg.h"
+
+const int MAX_ITERATIONS = 100 * 1000;
+const int NUM_TEST_STRS = 6;
+
+static bool is_escaped(const ACEXML_String& s)
+{
+ if (s[0] != ACE_TEXT('&'))
+ return false;
+ if (s[s.length() - 1] != ACE_TEXT(';'))
+ return false;
+ return true;
+}
+
+static int run_tests(ACEXML_String test_strings[NUM_TEST_STRS], int iterations)
+{
+ // Test 1 - Escape the strings using a new temporary string each iteration.
+ ACE_Time_Value start = ACE_OS::gettimeofday();
+ for (int i = 0; i < iterations; ++i)
+ {
+ ACEXML_String tmp = ACEXML_escape_string(test_strings[i % NUM_TEST_STRS]);
+ if (! is_escaped(tmp))
+ {
+ ACE_ERROR((LM_ERROR, "Error: Failed to escape string\n"));
+ return 1;
+ }
+ }
+ ACE_DEBUG((LM_DEBUG, "Test1 took %dms\n", (ACE_OS::gettimeofday() - start).msec()));
+
+ // Test 2 - Escape the strings using a shared temporary string. This shouldn't
+ // be any faster than Test 1 as long as the compiler has return value optimization.
+ ACEXML_String tmp;
+ start = ACE_OS::gettimeofday();
+ for (int i = 0; i < iterations; ++i)
+ {
+ tmp = ACEXML_escape_string(test_strings[i % NUM_TEST_STRS]);
+ if (! is_escaped(tmp))
+ {
+ ACE_ERROR((LM_ERROR, "Error: Failed to escape string\n"));
+ return 1;
+ }
+ }
+ ACE_DEBUG((LM_DEBUG, "Test2 took %dms\n", (ACE_OS::gettimeofday() - start).msec()));
+
+ // Test 3 - Escape the strings using a shared temporary string. This time, we use
+ // the alternate form of ACEXML_escape_string() so that our temporary buffer is reused.
+ tmp.clear(1);
+ start = ACE_OS::gettimeofday();
+ for (int i = 0; i < iterations; ++i)
+ {
+ ACEXML_escape_string(test_strings[i % NUM_TEST_STRS], tmp);
+ if (! is_escaped(tmp))
+ {
+ ACE_ERROR((LM_ERROR, "Error: Failed to escape string\n"));
+ return 1;
+ }
+ }
+ ACE_DEBUG((LM_DEBUG, "Test3 took %dms\n", (ACE_OS::gettimeofday() - start).msec()));
+
+ // Test 4 - Same as Test 3, except that the tmp buffer shouldn't have to resize.
+ start = ACE_OS::gettimeofday();
+ for (int i = 0; i < iterations; ++i)
+ {
+ ACEXML_escape_string(test_strings[i % NUM_TEST_STRS], tmp);
+ if (! is_escaped(tmp))
+ {
+ ACE_ERROR((LM_ERROR, "Error: Failed to escape string\n"));
+ return 1;
+ }
+ }
+ ACE_DEBUG((LM_DEBUG, "Test4 took %dms\n", (ACE_OS::gettimeofday() - start).msec()));
+ return 0;
+}
+
+int ACE_TMAIN (int, ACE_TCHAR *[])
+{
+ ACEXML_String test_strings[NUM_TEST_STRS] = {
+ ACE_TEXT("\"xxxxx\"xxxxxxxx xx\"xxxxxx xxxxxx\"xxxxxxxxxx xxxxxxxx\"xxxxxx\""),
+ ACE_TEXT("'xxxxx\'xxxxxxxx' xxxxxxxx xx'xxxxxxxx'xxxxxx xxxxxxx'xxxxxxx'"),
+ ACE_TEXT("&xxxx&xxxxxxxxx &xxxxxxxx xxxxx&xxxxxxxxxxx xxxx&xxxxxxxxxx&"),
+ ACE_TEXT(">xx>xxxxxxxxxxx >xxxxxxxx xxxxx>xxxxxxxxxxx xxxxx>xxxxxxxxx>"),
+ ACE_TEXT("<xxxxx<xxxxxxxx xxxxxxxx <xxxxxxxxxxxxxxx<x xxxxxxxxxxxxxx<"),
+ ACE_TEXT("&xxxx\"xxxxxxx&xx xxx'xxxxx xx<xxxxxxx>xxxxxxx xx\"xxxxxxxxxxxx>"),
+ };
+
+ if (run_tests(test_strings, MAX_ITERATIONS) != 0)
+ return 1;
+
+ ACE_DEBUG((LM_DEBUG, "Rerun tests with larger strings\n"));
+ for (int i = 0; i < NUM_TEST_STRS; ++i)
+ {
+ for (int j = 0; j < 5; ++j)
+ {
+ test_strings[i] += test_strings[i];
+ }
+ }
+
+ if (run_tests(test_strings, MAX_ITERATIONS / 10) != 0)
+ return 1;
+
+ return 0;
+}
diff --git a/ACEXML/tests/util/util.mpc b/ACEXML/tests/util/util.mpc
new file mode 100644
index 00000000000..892350c7bc8
--- /dev/null
+++ b/ACEXML/tests/util/util.mpc
@@ -0,0 +1,3 @@
+project: aceexe, acexml {
+ exename = test
+}
diff --git a/ChangeLog b/ChangeLog
index d49c1f23c84..f1168d8bad0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,38 @@
+Mon May 23 13:02:25 2005 Justin Michel <michel_j@ociweb.com>
+
+ * ACEXML/common/XML_Util.h:
+ * ACEXML/common/XML_Util.cpp:
+
+ Added new ACEXML_escape_string() functions to allow replacement of
+ illegal characters, (', ", &, <, >, etc.) with the escaped versions.
+ (&quot;, &lt;, etc.)
+
+ * ACEXML/tests/util/test.cpp:
+ * ACEXML/tests/util/util.mpc:
+
+ This is a performance test used while making the above functions, and
+ testing performance with ACE_String_Base.
+
+ * ace/String_Base.h:
+ * ace/String_Base.inl:
+ * ace/String_Base.cpp:
+
+ Fixed some documentation bugs, and added some new features to this class.
+ New efficient overloads for string concatenation.
+ Fixed clear(1) to work as documented.
+ Used a more optimal string growth when concatenating strings.
+ Performance optimizations for string concatenation.
+
+ * tests/SString_Test.cpp:
+
+ Test the new string concatenation overloads.
+
+ * bin/tao_other_tests.lst:
+
+ Enabled new ImR tests, and grouped all ImR tests together.
Mon May 23 12:26:19 2005 Steve Huston <shuston@riverace.com>
- * ace/Thread.h: Doxygen-ized the join() comments.
+ * ace/Thread.h: Doxygen-ized the join() comments.
Mon May 23 13:18:12 UTC 2005 Johnny Willemsen <jwillemsen@remedy.nl>
diff --git a/ace/String_Base.cpp b/ace/String_Base.cpp
index 77fe1c48529..687339b0a9c 100644
--- a/ace/String_Base.cpp
+++ b/ace/String_Base.cpp
@@ -20,13 +20,11 @@ ACE_RCSID (ace,
ACE_ALLOC_HOOK_DEFINE(ACE_String_Base)
template <class CHAR>
-CHAR ACE_String_Base<CHAR>::NULL_String_ = '\0';
+ CHAR ACE_String_Base<CHAR>::NULL_String_ = 0;
// this method might benefit from a little restructuring.
template <class CHAR> void
-ACE_String_Base<CHAR>::set (const CHAR *s,
- size_t len,
- int release)
+ACE_String_Base<CHAR>::set (const CHAR *s, size_t len, int release)
{
// Case 1. Going from memory to more memory
size_t new_buf_len = len + 1;
@@ -36,7 +34,7 @@ ACE_String_Base<CHAR>::set (const CHAR *s,
ACE_ALLOCATOR (temp,
(CHAR *) this->allocator_->malloc (new_buf_len * sizeof (CHAR)));
- if (this->release_)
+ if (this->buf_len_ != 0 && this->release_ != 0)
this->allocator_->free (this->rep_);
this->rep_ = temp;
@@ -44,41 +42,37 @@ ACE_String_Base<CHAR>::set (const CHAR *s,
this->release_ = 1;
this->len_ = len;
ACE_OS::memcpy (this->rep_, s, len * sizeof (CHAR));
- // NUL terminate.
- this->rep_[len] = '\0';
+ this->rep_[len] = 0;
}
-
- // Case 2. No memory allocation is necessary.
- else
+ else // Case 2. No memory allocation is necessary.
{
// Free memory if necessary and figure out future ownership
- if (!release || s == 0 || len == 0)
+ if (release == 0 || s == 0 || len == 0)
{
- if (this->release_)
+ if (this->buf_len_ != 0 && this->release_ != 0)
{
this->allocator_->free (this->rep_);
this->release_ = 0;
}
}
- // else - stay with whatever value for release_ we have.
-
// Populate data.
if (s == 0 || len == 0)
{
this->buf_len_ = 0;
this->len_ = 0;
this->rep_ = &ACE_String_Base<CHAR>::NULL_String_;
+ this->release_ = 0;
}
- else if (!release)
+ else if (release == 0) // Note: No guarantee that rep_ is null terminated.
{
this->buf_len_ = len;
this->len_ = len;
this->rep_ = const_cast <CHAR *> (s);
+ this->release_ = 0;
}
else
{
ACE_OS::memcpy (this->rep_, s, len * sizeof (CHAR));
- // NUL terminate.
this->rep_[len] = 0;
this->len_ = len;
}
@@ -87,8 +81,7 @@ ACE_String_Base<CHAR>::set (const CHAR *s,
// Return substring.
template <class CHAR> ACE_String_Base<CHAR>
-ACE_String_Base<CHAR>::substring (size_t offset,
- ssize_t length) const
+ACE_String_Base<CHAR>::substring (size_t offset, ssize_t length) const
{
ACE_String_Base<CHAR> nill;
size_t count = length;
@@ -107,59 +100,48 @@ ACE_String_Base<CHAR>::substring (size_t offset,
else if (length == -1 || count > (this->len_ - offset))
count = this->len_ - offset;
- return ACE_String_Base<CHAR> (&this->rep_[offset],
- count,
- this->allocator_);
+ return ACE_String_Base<CHAR> (&this->rep_[offset], count, this->allocator_);
}
-// Concat operator (does copy memory).
-
template <class CHAR> ACE_String_Base<CHAR> &
-ACE_String_Base<CHAR>::operator+= (const ACE_String_Base<CHAR> &s)
+ACE_String_Base<CHAR>::append (const CHAR* s, size_t slen)
{
- ACE_TRACE ("ACE_String_Base<CHAR>::operator+=");
-
- if (s.len_ > 0)
+ ACE_TRACE ("ACE_String_Base<CHAR>::append(const CHAR*, size_t)");
+ if (slen > 0)
+ {
+ // case 1. No memory allocation needed.
+ if (this->buf_len_ >= this->len_ + slen + 1)
{
- const size_t new_buf_len = this->len_ + s.len_ + 1;
-
- // case 1. No memory allocation needed.
- if (this->buf_len_ >= new_buf_len)
- // Copy in data from new string.
- ACE_OS::memcpy (this->rep_ + this->len_,
- s.rep_,
- s.len_ * sizeof (CHAR));
- // case 2. Memory reallocation is needed
- else
- {
- CHAR *t = 0;
+ // Copy in data from new string.
+ ACE_OS::memcpy (this->rep_ + this->len_, s, slen * sizeof (CHAR));
+ }
+ else // case 2. Memory reallocation is needed
+ {
+ const size_t new_buf_len =
+ ace_max(this->len_ + slen + 1, this->buf_len_ + this->buf_len_ / 2);
- ACE_ALLOCATOR_RETURN (t,
- (CHAR *) this->allocator_->malloc (new_buf_len *
- sizeof (CHAR)),
- *this);
+ CHAR *t = 0;
- // Copy memory from old string into new string.
- ACE_OS::memcpy (t,
- this->rep_,
- this->len_ * sizeof (CHAR));
+ ACE_ALLOCATOR_RETURN (t,
+ (CHAR *) this->allocator_->malloc (new_buf_len * sizeof (CHAR)), *this);
- ACE_OS::memcpy (t + this->len_,
- s.rep_,
- s.len_ * sizeof (CHAR));
+ // Copy memory from old string into new string.
+ ACE_OS::memcpy (t, this->rep_, this->len_ * sizeof (CHAR));
- if (this->release_)
- this->allocator_->free (this->rep_);
+ ACE_OS::memcpy (t + this->len_, s, slen * sizeof (CHAR));
- this->release_ = 1;
- this->rep_ = t;
- this->buf_len_ = new_buf_len;
- }
+ if (this->buf_len_ != 0 && this->release_ != 0)
+ this->allocator_->free (this->rep_);
- this->len_ += s.len_;
- this->rep_[this->len_] = '\0';
+ this->release_ = 1;
+ this->rep_ = t;
+ this->buf_len_ = new_buf_len;
}
+ this->len_ += slen;
+ this->rep_[this->len_] = 0;
+ }
+
return *this;
}
@@ -180,19 +162,37 @@ ACE_String_Base<CHAR>::resize (size_t len, CHAR c)
// Only reallocate if we don't have enough space...
if (this->buf_len_ <= len)
{
- if (this->buf_len_ != 0 && this->release_)
+ if (this->buf_len_ != 0 && this->release_ != 0)
this->allocator_->free (this->rep_);
- this->rep_ = (CHAR *)
- this->allocator_->malloc ((len + 1) * sizeof (CHAR));
+ this->rep_ = static_cast<CHAR*>(
+ this->allocator_->malloc ((len + 1) * sizeof (CHAR)));
this->buf_len_ = len + 1;
this->release_ = 1;
}
+ this->len_ = 0;
+ ACE_OS::memset (this->rep_, c, this->buf_len_ * sizeof (CHAR));
+}
+template <class CHAR> void
+ACE_String_Base<CHAR>::clear (int release)
+{
+ // This can't use set(), because that would free memory if release=0
+ if (release != 0)
+ {
+ if (this->buf_len_ != 0 && this->release_ != 0)
+ this->allocator_->free (this->rep_);
+
+ this->rep_ = &ACE_String_Base<CHAR>::NULL_String_;
this->len_ = 0;
- ACE_OS::memset (this->rep_,
- c,
- this->buf_len_ * sizeof (CHAR));
+ this->buf_len_ = 0;
+ this->release_ = 0;
}
+ else
+ {
+ this->fast_clear ();
+ }
+}
+
#endif /* ACE_STRING_BASE_CPP */
diff --git a/ace/String_Base.h b/ace/String_Base.h
index 228a0a675e4..a1c93158faa 100644
--- a/ace/String_Base.h
+++ b/ace/String_Base.h
@@ -24,7 +24,6 @@
#include "ace/Global_Macros.h"
-// Forward decl.
class ACE_Allocator;
/**
@@ -58,9 +57,12 @@ public:
/**
* Constructor that copies @a s into dynamically allocated memory.
- * If @a release is non-0 then the @a ACE_Allocator is responsible for
- * freeing this memory. Memory is _not_ allocated/freed if @a release
- * is 0.
+ *
+ * if release == 1 then a new buffer is allocated internally, and
+ * s is copied to the internal buffer.
+ * if release == 0 then the s buffer is used directly. If s == 0
+ * then it will _not_ be used, and instead the internal buffer
+ * is set to NULL_String_.
*
* @param s Zero terminated input string
* @param the_allocator ACE_Allocator associated with string
@@ -74,9 +76,13 @@ public:
/**
* Constructor that copies @a len CHARs of @a s into dynamically
- * allocated memory (will zero terminate the result). If @a release
- * is non-0 then the @a ACE_allocator is responsible for freeing this
- * memory. Memory is _not_ allocated/freed if @a release is 0.
+ * allocated memory (will zero terminate the result).
+ *
+ * if release == 1 then a new buffer is allocated internally.
+ * s is copied to the internal buffer.
+ * if release == 0 then the s buffer is used directly. If s == 0
+ * then it will _not_ be used, and instead the internal buffer
+ * is set to NULL_String_.
*
* @param s Non-zero terminated input string
* @param len Length of non-zero terminated input string
@@ -105,17 +111,20 @@ public:
* @param the_allocator ACE_Allocator associated with string
* @return ACE_String_Base containing CHAR 'c'
*/
- ACE_String_Base (CHAR c,
- ACE_Allocator *the_allocator = 0);
+ ACE_String_Base (CHAR c, ACE_Allocator *the_allocator = 0);
/**
- * Constructor that dynamically allocate @a len long of char array
- * and initialize it to @a c using @a alloc to allocate the memory.
+ * Constructor that allocates a len long string.
+ *
+ * Warning : This constructor was incorrectly documented in the past.
+ * It simply calls resize(len, c).
+ * It is probably not advisable to use the second parameter. See
+ * resize() for more information.
*
- * @param len Length of character array 'c'
- * @param c Input character array
+ * @param len Amount of space to reserve for the string.
+ * @param c The array is filled with c's
* @param the_allocator ACE_Allocator associated with string
- * @return ACE_String_Base containing character array 'c'
+ * @return Empty ACE_String_Base with room for len CHARs
*/
ACE_String_Base (size_t len,
CHAR c = 0,
@@ -161,8 +170,17 @@ public:
ACE_String_Base < CHAR > &assign_nocopy (const ACE_String_Base < CHAR > &s);
/**
- * Copy @a s into this @a ACE_String_Base. Memory is _not_
- * allocated/freed if @a release is 0.
+ * Copy @a s into this @a ACE_String_Base.
+ *
+ * If release == 1 then a new buffer is allocated internally if the
+ * existing one is not big enough to hold s. If the existing
+ * buffer is big enough, then it will be used. This means that
+ * set(*, 1) can be illegal when the string is constructed with a
+ * const char*. (e.g. ACE_String_Base("test", 0, 0)).
+ *
+ * if release == 0 then the s buffer is used directly, and any
+ * existing buffer is destroyed. If s == 0 then it will _not_ be
+ * used, and instead the internal buffer is set to NULL_String_.
*
* @param s Null terminated input string
* @param release Allocator responsible(1)/not reponsible(0) for
@@ -172,7 +190,16 @@ public:
/**
* Copy @a len bytes of @a s (will zero terminate the result).
- * Memory is _not_ allocated/freed if @a release is 0.
+ *
+ * If release == 1 then a new buffer is allocated internally if the
+ * existing one is not big enough to hold s. If the existing
+ * buffer is big enough, then it will be used. This means that
+ * set(*, *, 1) is illegal when the string is constructed with a
+ * non-owned const char*. (e.g. ACE_String_Base("test", 0, 0))
+ *
+ * If release == 0 then the s buffer is used directly, and any
+ * existing buffer is destroyed. If s == 0 then it will _not_ be
+ * used, and instead the internal buffer is set to NULL_String_.
*
* @param s Non-zero terminated input string
* @param len Length of input string 's'
@@ -184,6 +211,12 @@ public:
/**
* Clear this string. Memory is _not_ freed if <release> is 0.
*
+ * Warning: This method was incorrectly documented in the past, but
+ * the current implementation has been changed to match the documented
+ * behavior.
+ *
+ * Warning: clear(0) behaves like fast_clear() below.
+ *
* @param release Memory is freed if 1 or not if 0.
*/
void clear (int release = 0);
@@ -199,6 +232,12 @@ public:
* - the buffer pointer is reset to the NULL_String_ and does not
* maintain a pointer to the caller-supplied buffer on return
* - the maximum string length is reset to 0.
+ *
+ * Warning : Calling clear(0) or fast_clear() can have unintended
+ * side-effects if the string was constructed (or set()) with an
+ * external buffer. The string will be disassociated with the buffer
+ * and the next append() or +=() will cause a new buffer to be
+ * allocated internally.
*/
void fast_clear (void);
@@ -226,13 +265,41 @@ public:
/**
* Concat operator (copies memory).
*
- * @param s Input ACE_String_Base string to concatenate to another string.
+ * @param s Input ACE_String_Base string to concatenate to this string.
* @return The combined string (input append to the end of the old). New
* string is zero terminated.
*/
ACE_String_Base < CHAR > &operator += (const ACE_String_Base < CHAR > &s);
/**
+ * Concat operator (copies memory).
+ *
+ * @param s Input C string to concatenate to this string.
+ * @return The combined string (input append to the end of the old). New
+ * string is zero terminated.
+ */
+ ACE_String_Base < CHAR >& operator += (const CHAR* s);
+
+ /**
+ * Concat operator (copies memory).
+ *
+ * @param c Input CHAR to concatenate to this string.
+ * @return The combined string (input append to the end of the old). New
+ * string is zero terminated.
+ */
+ ACE_String_Base < CHAR >& operator += (const CHAR c);
+
+ /**
+ * Append function (copies memory).
+ *
+ * @param s Input CHAR array to concatenate to this string.
+ * @param slen The length of the array.
+ * @return The combined string (input append to the end of the old). New
+ * string is zero terminated.
+ */
+ ACE_String_Base < CHAR >& append (const CHAR* s, size_t slen);
+
+ /**
* Returns a hash value for this string.
*
* @return Hash value of string
@@ -375,12 +442,19 @@ public:
/**
* This method is designed for high-performance. Please use with
- * care ;-) If the current size of the string is less than <len>,
- * the string is resized to the new length. The data is zero'd
- * out after this operation.
- *
- * @param len New string size
- * @param c New input string
+ * care ;-)
+ *
+ * Warning : This method was documented incorrectly in the past.
+ * The original intention was to change the length of the string to
+ * len, and to fill the whole thing with c CHARs.
+ * However, what was actually done was to set the length of the
+ * string to zero, and fill the buffer with c's. The buffer was
+ * also not null-terminated unless c happened to be zero.
+ * Rather than fix the method to work as documented, the code is
+ * left as is, but the second parameter should probably not be used.
+ *
+ * @param len The number of CHARs to reserve
+ * @param c The CHAR to use when filling the string.
*/
void resize (size_t len, CHAR c = 0);
diff --git a/ace/String_Base.inl b/ace/String_Base.inl
index 90434d23b76..46e0c43f011 100644
--- a/ace/String_Base.inl
+++ b/ace/String_Base.inl
@@ -34,14 +34,7 @@ ACE_String_Base<CHAR>::ACE_String_Base (const CHAR *s,
release_ (0)
{
ACE_TRACE ("ACE_String_Base<CHAR>::ACE_String_Base");
-
- size_t length;
- if (s != 0)
- length = ACE_OS::strlen (s);
- else
- length = 0;
-
- this->set (s, length, release);
+ this->set (s, release);
}
template <class CHAR> ACE_INLINE
@@ -109,7 +102,8 @@ ACE_String_Base<CHAR>::~ACE_String_Base (void)
{
ACE_TRACE ("ACE_String_Base<CHAR>::~ACE_String_Base");
- this->set (0, 0, 0);
+ if (this->buf_len_ != 0 && this->release_ != 0)
+ this->allocator_->free (this->rep_);
}
template <class CHAR> ACE_INLINE void
@@ -146,11 +140,9 @@ ACE_String_Base<CHAR>::assign_nocopy (const ACE_String_Base<CHAR> &s)
template <class CHAR> ACE_INLINE void
ACE_String_Base<CHAR>::set (const CHAR *s, int release)
{
- size_t length;
+ size_t length = 0;
if (s != 0)
length = ACE_OS::strlen (s);
- else
- length = 0;
this->set (s, length, release);
}
@@ -163,16 +155,10 @@ ACE_String_Base<CHAR>::length (void) const
}
template <class CHAR> ACE_INLINE void
-ACE_String_Base<CHAR>::clear (int release)
-{
- this->set(0, 0, release);
-}
-
-template <class CHAR> ACE_INLINE void
ACE_String_Base<CHAR>::fast_clear (void)
{
this->len_ = 0;
- if (this->release_)
+ if (this->release_ != 0)
{
// String retains the original buffer.
if (this->rep_ != &ACE_String_Base<CHAR>::NULL_String_)
@@ -241,7 +227,10 @@ template <class CHAR> ACE_INLINE int
ACE_String_Base<CHAR>::compare (const ACE_String_Base<CHAR> &s) const
{
ACE_TRACE ("ACE_String_Base<CHAR>::compare");
-
+
+ if (this->rep_ == s.rep_)
+ return 0;
+
// Pick smaller of the two lengths and perform the comparison.
size_t smaller_length = ace_min (this->len_, s.len_);
@@ -261,7 +250,8 @@ template <class CHAR> ACE_INLINE bool
ACE_String_Base<CHAR>::operator== (const ACE_String_Base<CHAR> &s) const
{
ACE_TRACE ("ACE_String_Base<CHAR>::operator==");
-
+ if (this->len_ != s.len_)
+ return false;
return compare (s) == 0;
}
@@ -346,7 +336,8 @@ ACE_String_Base<CHAR>::rfind (CHAR c, ssize_t pos) const
template <class CHAR> ACE_INLINE ACE_String_Base<CHAR>
operator+ (const ACE_String_Base<CHAR> &s, const ACE_String_Base<CHAR> &t)
{
- ACE_String_Base<CHAR> temp (s);
+ ACE_String_Base<CHAR> temp (s.length() + t.length());
+ temp += s;
temp += t;
return temp;
}
@@ -354,7 +345,12 @@ operator+ (const ACE_String_Base<CHAR> &s, const ACE_String_Base<CHAR> &t)
template <class CHAR> ACE_INLINE ACE_String_Base<CHAR>
operator+ (const CHAR *s, const ACE_String_Base<CHAR> &t)
{
- ACE_String_Base<CHAR> temp (s);
+ size_t slen = 0;
+ if (s != 0)
+ slen = ACE_OS::strlen (s);
+ ACE_String_Base<CHAR> temp (slen + t.length());
+ if (slen > 0)
+ temp.append(s, slen);
temp += t;
return temp;
}
@@ -362,8 +358,13 @@ operator+ (const CHAR *s, const ACE_String_Base<CHAR> &t)
template <class CHAR> ACE_INLINE ACE_String_Base<CHAR>
operator+ (const ACE_String_Base<CHAR> &s, const CHAR *t)
{
- ACE_String_Base<CHAR> temp (s);
- temp += t;
+ size_t tlen = 0;
+ if (t != 0)
+ tlen = ACE_OS::strlen (t);
+ ACE_String_Base<CHAR> temp (s.length() + tlen);
+ temp += s;
+ if (tlen > 0)
+ temp.append(t, tlen);
return temp;
}
@@ -371,7 +372,8 @@ template <class CHAR> ACE_INLINE
ACE_String_Base<CHAR> operator + (const ACE_String_Base<CHAR> &t,
const CHAR c)
{
- ACE_String_Base<CHAR> temp (t);
+ ACE_String_Base<CHAR> temp (t.length() + 1);
+ temp += t;
temp += c;
return temp;
}
@@ -380,7 +382,30 @@ template <class CHAR> ACE_INLINE
ACE_String_Base<CHAR> operator + (const CHAR c,
const ACE_String_Base<CHAR> &t)
{
- ACE_String_Base<CHAR> temp (c);
+ ACE_String_Base<CHAR> temp (t.length() + 1);
+ temp += c;
temp += t;
return temp;
}
+
+template <class CHAR> ACE_INLINE ACE_String_Base<CHAR> &
+ACE_String_Base<CHAR>::operator+= (const ACE_String_Base<CHAR> &s)
+{
+ return this->append(s.rep_, s.len_);
+}
+
+template <class CHAR> ACE_INLINE ACE_String_Base<CHAR> &
+ACE_String_Base<CHAR>::operator+= (const CHAR* s)
+{
+ size_t slen = 0;
+ if (s != 0)
+ slen = ACE_OS::strlen (s);
+ return this->append(s, slen);
+}
+
+template <class CHAR> ACE_INLINE ACE_String_Base<CHAR> &
+ACE_String_Base<CHAR>::operator+= (const CHAR c)
+{
+ const size_t slen = 1;
+ return this->append(&c, slen);
+}
diff --git a/bin/tao_other_tests.lst b/bin/tao_other_tests.lst
index 7ad94bb2b37..e8245108c1a 100644
--- a/bin/tao_other_tests.lst
+++ b/bin/tao_other_tests.lst
@@ -84,16 +84,22 @@ TAO/orbsvcs/tests/EC_MT_Mcast/run_test.pl:!ST !MINIMUM !STATIC
TAO/orbsvcs/tests/FaultTolerance/GroupRef_Manipulation/run_test.pl:!MINIMUM !DISABLE_INTERCEPTORS
TAO/orbsvcs/tests/FaultTolerance/IOGR/run_test.pl:!MINIMUM !DISABLE_INTERCEPTORS
TAO/orbsvcs/tests/FaultTolerance/IOGRManipulation/run_test.pl:!MINIMUM !DISABLE_INTERCEPTORS
-TAO/orbsvcs/tests/ImplRepo/run_test.pl: !MINIMUM
-TAO/orbsvcs/tests/ImplRepo/NameService/run_test.pl: !MINIMUM
TAO/orbsvcs/tests/InterfaceRepo/Application_Test/run_test.pl: !MINIMUM !NO_IFR
TAO/orbsvcs/tests/InterfaceRepo/IDL3_Test/run_test.pl: !MINIMUM !NO_IFR
TAO/orbsvcs/tests/InterfaceRepo/IFR_Test/run_test.pl: !MINIMUM !NO_IFR
TAO/orbsvcs/tests/InterfaceRepo/Latency_Test/run_test.pl: !MINIMUM !NO_IFR
TAO/orbsvcs/tests/InterfaceRepo/Persistence_Test/run_test.pl: !MINIMUM !NO_IFR
+TAO/orbsvcs/tests/ImplRepo/run_test.pl both_ir: !MINIMUM
+TAO/orbsvcs/tests/ImplRepo/run_test.pl nestea_ir: !MINIMUM
+TAO/orbsvcs/tests/ImplRepo/run_test.pl airplane_ir: !MINIMUM
+TAO/orbsvcs/tests/ImplRepo/run_test.pl persistent_ir: !MINIMUM
+TAO/orbsvcs/tests/ImplRepo/run_test.pl nt_service_ir: !MINIMUM Win32
+TAO/orbsvcs/tests/ImplRepo/run_test.pl shutdown: !MINIMUM
+TAO/orbsvcs/tests/ImplRepo/run_test.pl perclient: !MINIMUM
+TAO/orbsvcs/tests/ImplRepo/NameService/run_test.pl: !MINIMUM
TAO/orbsvcs/tests/ImplRepo/locked/run_test.pl: !MINIMUM
-TAO/orbsvcs/tests/ImplRepo/scale/run_test.pl: !MINIMUM
-TAO/orbsvcs/examples/ImR/Combined_Service/run_test.pl: !MINIMUM !STATIC !ST Exceptions
+TAO/orbsvcs/tests/ImplRepo/scale/run_test.pl -servers 5 -objects 5: !MINIMUM
+TAO/orbsvcs/examples/ImR/Combined_Service/run_test.pl: !MINIMUM !STATIC !ST
TAO/orbsvcs/tests/Log/Basic_Log_Test/run_test.pl: !NO_MESSAGING
TAO/orbsvcs/tests/Notify/Basic/run_test.pl notify.reactive.conf: !ST !NO_MESSAGING !STATIC !MINIMUM
TAO/orbsvcs/tests/Notify/Basic/run_test.pl notify.mt.conf: !ST !NOTIFY !NO_MESSAGING !MINIMUM
diff --git a/tests/SString_Test.cpp b/tests/SString_Test.cpp
index 971a9c50aee..a6726e7a9fb 100644
--- a/tests/SString_Test.cpp
+++ b/tests/SString_Test.cpp
@@ -25,6 +25,47 @@
ACE_RCSID(tests, SString_Test, "$Id$")
+static int testConcatenation() {
+#ifdef ACE_HAS_WCHAR
+ ACE_WString s1;
+ s1 += L'H';
+ if (s1 != ACE_WString(L"H")) {
+ ACE_ERROR((LM_ERROR, "Concat wchar_t\n"));
+ return 1;
+ }
+ s1 = ACE_WString(L"Hello");
+ s1 += L" World";
+ if (s1 != ACE_WString(L"Hello World")) {
+ ACE_ERROR((LM_ERROR, "Concat wchar_t*\n"));
+ return 1;
+ }
+ s1 = L"Hello";
+ s1 += ACE_WString(L" World");
+ if (s1 != ACE_WString(L"Hello World")) {
+ ACE_ERROR((LM_ERROR, "Concat wstring\n"));
+ return 1;
+ }
+ s1 = L"Hello";
+ s1.append(L" World", 6);
+ if (s1 != ACE_WString(L"Hello World")) {
+ ACE_ERROR((LM_ERROR, "Concat wchar_t* 2\n"));
+ return 1;
+ }
+ s1 += L'.';
+ if (s1 != ACE_WString(L"Hello World.")) {
+ ACE_ERROR((LM_ERROR, "Concat wchar_t\n"));
+ return 1;
+ }
+ ACE_WString s2(L"Hello World");
+ s2 += L'.';
+ if (s2 != ACE_WString(L"Hello World.")) {
+ ACE_ERROR((LM_ERROR, "Concat wchar_t 2\n"));
+ return 1;
+ }
+#endif /* ACE_HAS_WCHAR */
+ return 0;
+}
+
int
run_main (int, ACE_TCHAR *[])
{
@@ -47,46 +88,46 @@ run_main (int, ACE_TCHAR *[])
ACE_CString zero_size_string (s1.c_str (), 0, 0, 1);
// 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"));}
+ if (s1 == s2){ACE_ERROR((LM_ERROR,"Set #1:\n"));return 1;}
+ if (s1 == s5){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
// 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"));}
+ if (s1 != s1){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
+ if (s1 != s0){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
// 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"));}
+ if (s1.strstr (s2) != -1){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
+ if (s1.strstr (s3) != 2){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
+ if (s3.strstr (s1) != -1){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
+ if (s1.strstr (s4) != 1){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
// 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"));}
+ if (s1.substring (0) != s1){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
+ if (s1.substring (1) != s4){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
+ if (s1.substring (2, 2) != s3){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
+ if (s1.substring (0, 0) != empty_string){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
+ if (s1.substring (4, 10).length () != 1){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
// 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"));}
+ if (s1.find (s3) != 2){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
+ if (s3.find (s1) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
+ if (s1.find (s3, 2) != 2){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
+ if (s3.find (s1, 1) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
+ if (s1.find (s2) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
+ if (s1.find ('o') != 4){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
// 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"));}
+ if (s1.rfind ('l') != 3){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
+ if (s1.rfind ('l', 3) != 2){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
// Assignment. Error if they are not equal
ACE_CString s6;
s6 = s0;
- if (s6 != s0){ACE_ERROR((LM_ERROR,"Set #1: \n"));}
+ if (s6 != s0){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
s6 = s4;
- if (s4 != s6){ACE_ERROR((LM_ERROR,"Set #1: \n"));}
+ if (s4 != s6){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
s6 = s5;
- if (s6 != s5){ACE_ERROR((LM_ERROR,"Set #1: \n"));}
+ if (s6 != s5){ACE_ERROR((LM_ERROR,"Set #1: \n"));return 1;}
}
{
@@ -105,49 +146,49 @@ run_main (int, ACE_TCHAR *[])
ACE_CString zero_size_string (s1.c_str (), 0, 0, 0);
// 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"));}
+ if (s1 == s2){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
+ if (s1 == s5){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
// 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"));}
+ if (s1 != s1){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
+ if (s1 != s0){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
// 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"));}
+ if (s1.strstr (s2) != -1){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
+ if (s1.strstr (s3) != 2){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
+ if (s3.strstr (s1) != -1){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
+ if (s1.strstr (s4) != 1){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
// 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"));}
+ if (s1.substring (0) != s1){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
+ if (s1.substring (1) != s4){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
+ if (s1.substring (2, 2) != s3){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
+ if (s1.substring (0, 0) != empty_string){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
// 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"));}
+ if (s1.find (s3) != 2){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
+ if (s3.find (s1) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
+ if (s1.find (s3, 2) != 2){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
+ if (s3.find (s1, 1) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
+ if (s1.find (s2) != ACE_CString::npos){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
+ if (s1.find ('o') != 4){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
// 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"));}
+ if (s1.rfind ('l') != 3){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
+ if (s1.rfind ('l', 3) != 2){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
// Assignment. Error if they are not equal
ACE_CString s6;
s6 = s0;
- if (s6 != s0){ACE_ERROR((LM_ERROR,"Set #2: \n"));}
+ if (s6 != s0){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
s6 = s4;
- if (s4 != s6){ACE_ERROR((LM_ERROR,"Set #2: \n"));}
+ if (s4 != s6){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
s6 = s5;
- if (s6 != s5){ACE_ERROR((LM_ERROR,"Set #2: \n"));}
+ if (s6 != s5){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
// Clear. Error if they are not equal
s0.clear();
- if (s0.length() != 0){ACE_ERROR((LM_ERROR,"Set #2: \n"));}
+ if (s0.length() != 0){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
// Rep. Error if they are not equal
ACE_Auto_Basic_Array_Ptr<char> s (s1.rep ());
@@ -157,7 +198,7 @@ run_main (int, ACE_TCHAR *[])
};
ACE_CString s7 (s.get ());
- if (s1 != s7){ACE_ERROR((LM_ERROR,"Set #2: \n"));}
+ if (s1 != s7){ACE_ERROR((LM_ERROR,"Set #2: \n"));return 1;}
}
{
@@ -177,50 +218,50 @@ run_main (int, ACE_TCHAR *[])
ACE_NS_WString zero_size_string (s1.c_str (), 0, 0);
// 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"));}
- if (s1 == s6){ACE_ERROR((LM_ERROR,"Set #3: off-by-one failed\n"));}
+ if (s1 == s2){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
+ if (s1 == s5){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
+ if (s1 == s6){ACE_ERROR((LM_ERROR,"Set #3: off-by-one failed\n"));return 1;}
// 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"));}
+ if (s1 != s1){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
+ if (s1 != s0){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
// 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"));}
+ if (s1.strstr (s2) != -1){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
+ if (s1.strstr (s3) != 2){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
+ if (s3.strstr (s1) != -1){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
+ if (s1.strstr (s4) != 1){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
// 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"));}
+ if (s1.substring (0) != s1){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
+ if (s1.substring (1) != s4){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
+ if (s1.substring (2, 2) != s3){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
+ if (s1.substring (0, 0) != empty_string){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
// 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"));}
+ if (s1.find (s3) != 2){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
+ if (s3.find (s1) != ACE_WString::npos){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
+ if (s1.find (s3, 2) != 2){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
+ if (s3.find (s1, 1) != ACE_WString::npos){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
+ if (s1.find (s2) != ACE_WString::npos){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
+ if (s1.find ('o') != 4){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
// 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"));}
+ if (s1.rfind ('l') != 3){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
+ if (s1.rfind ('l', 3) != 2){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
// Assignment. Error if they are not equal
ACE_NS_WString s7;
s7 = s0;
- if (s7 != s0){ACE_ERROR((LM_ERROR,"Set #3: \n"));}
+ if (s7 != s0){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
s7 = s4;
- if (s4 != s7){ACE_ERROR((LM_ERROR,"Set #3: \n"));}
+ if (s4 != s7){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
s7 = s5;
- if (s7 != s5){ACE_ERROR((LM_ERROR,"Set #3: \n"));}
+ if (s7 != s5){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
// Clear. Error if they are not equal
s0.clear();
- if (s0.length() != 0){ACE_ERROR((LM_ERROR,"Set #3: \n"));}
+ if (s0.length() != 0){ACE_ERROR((LM_ERROR,"Set #3: \n"));return 1;}
}
{
@@ -228,44 +269,44 @@ run_main (int, ACE_TCHAR *[])
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"));}
+ if (s1 == s2){ACE_ERROR((LM_ERROR,"Set #4: \n"));return 1;}
+ if (!(s1 > s2)){ACE_ERROR((LM_ERROR,"Set #4: \n"));return 1;}
+ if (s1 < s2){ACE_ERROR((LM_ERROR,"Set #4: \n"));return 1;}
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"));}
+ if (s3 == s4){ACE_ERROR((LM_ERROR,"Set #4: \n"));return 1;}
+ if (!(s3 < s4)){ACE_ERROR((LM_ERROR,"Set #4: \n"));return 1;}
+ if (s3 > s4){ACE_ERROR((LM_ERROR,"Set #4: \n"));return 1;}
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"));}
+ if(s5 == s6){ACE_ERROR((LM_ERROR,"Set #4: \n"));return 1;}
+ if(!(s5 < s6)){ACE_ERROR((LM_ERROR,"Set #4: \n"));return 1;}
+ if(s5 > s6){ACE_ERROR((LM_ERROR,"Set #4: \n"));return 1;}
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"));}
+ if(s7 == s8){ACE_ERROR((LM_ERROR,"Set #4: \n"));return 1;}
+ if(!(s7 > s8)){ACE_ERROR((LM_ERROR,"Set #4: \n"));return 1;}
+ if(s7 < s8){ACE_ERROR((LM_ERROR,"Set #4: \n"));return 1;}
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"));}
+ if(s9 == s10){ACE_ERROR((LM_ERROR,"Set #4: \n"));return 1;}
+ if(!(s9 < s10)){ACE_ERROR((LM_ERROR,"Set #4: \n"));return 1;}
+ if(s9 > s10){ACE_ERROR((LM_ERROR,"Set #4: \n"));return 1;}
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"));}
+ if(s11 == s12){ACE_ERROR((LM_ERROR,"Set #4: \n"));return 1;}
+ if(!(s11 > s12)){ACE_ERROR((LM_ERROR,"Set #4: \n"));return 1;}
+ if(s11 < s12){ACE_ERROR((LM_ERROR,"Set #4: \n"));return 1;}
s11.fast_clear ();
if (s11.length () != 0)
@@ -278,16 +319,18 @@ run_main (int, ACE_TCHAR *[])
const char *str = "What_a_day_it_has_been";
- sstr.rep (const_cast<char *> (str));
+ sstr.rep (const_cast<char *>(str));
ACE_SString tmp =
sstr.substring (2, 300);
if (tmp.length () == 300)
- ACE_ERROR ((LM_ERROR,
- "SString substring \n"));
+ ACE_ERROR ((LM_ERROR, "SString substring \n"));
}
+
+ int err = testConcatenation();
+
ACE_END_TEST;
- return 0;
+ return err;
}