first commit

This commit is contained in:
Jose Caban
2025-06-07 11:34:38 -04:00
commit 0eb2d7c07d
4708 changed files with 1500614 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
/************************************************************************
*
* 18.limits.stdcxx-436.cpp - test case from STDCXX-436 issue
*
* $Id: 18.limits.stdcxx-436.cpp 580483 2007-09-28 20:55:52Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <assert.h> // for assert()
#include <limits.h> // for MB_LEN_MAX
// tell Compaq C++ we need the declaration of the POSIX popen() function
// that's guarded (not declared) in the compiler's pure C++ libc headers
#undef __PURE_CNAME
#include <stdio.h> // for popen(), fscanf(), pclose(), ...
#if defined(_WIN32) || defined(_WIN64)
# define popen _popen
# define pclose _pclose
#endif // defined(_WIN32) || defined(_WIN64)
int main ()
{
// assumes getconf is in the path. on most unix systems it is in
// '/usr/bin' and it doesn't exist on most win32 configurations,
// yet somehow this appears to work on windows, but not sure how.
FILE* f = popen ("getconf MB_LEN_MAX", "r");
if (f) {
int mb_len_max = -1;
const bool failed = fscanf (f, "%d", &mb_len_max) != 1;
pclose (f);
// if getconf isn't available, or getconf doesn't know the limit
// the scan will fail, so we must handle both situations.
assert (failed || MB_LEN_MAX == mb_len_max);
}
return 0;
}

View File

@@ -0,0 +1,81 @@
/************************************************************************
*
* 18.limits.traps.stdcxx-624.cpp - regression test for STDCXX-624
*
* $Id: 18.limits.traps.stdcxx-624.cpp 642845 2008-03-30 23:53:44Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert> // for assert()
#include <csignal> // for SIGFPE and signal()
#include <cstdlib> // for strtod()
#include <limits> // for numeric_limits
char digits[] = " +0.?23456789e+01";
volatile int result;
extern "C" {
void handle_FPE (int)
{
// if we get here (presumably in response to SIGFPE triggered
// by a trap in integer arithmetic) verify that numeric_limits
// traps is non-zero and successfuly exit the process
assert (std::numeric_limits<int>::traps);
std::exit (0);
}
} // extern "C"
int main ()
{
// prevent clever optimizers from figuring out that (zero == 0)
digits [4] = '0';
const int zero = (int)std::strtod (digits, 0);
// compute a non-zero integer value
digits [4] = '1';
const int non_zero = (int)std::strtod (digits, 0);
// set up a handler for the FPE signal only when traps is true
// otherwise expect to be able to perform integer arithmetic
// without a signal
if (std::numeric_limits<int>::traps)
std::signal (SIGFPE, handle_FPE);
// if this traps (generates SIGFPE), verify (in the signal handler)
// that integer arithmetic is expected to trap
result = non_zero / zero;
result += non_zero % zero;
// if we get this far, verify that integer arithmetic is known not
// to trap
assert (!std::numeric_limits<int>::traps);
(void)&result;
return 0;
}

View File

@@ -0,0 +1,49 @@
/**************************************************************************
*
* 20.specialized.stdcxx-390.cpp - regression test for STDCXX-390
*
* http://issues.apache.org/jira/browse/STDCXX-390
*
* $Id: 20.specialized.stdcxx-390.cpp 580483 2007-09-28 20:55:52Z sebor $
*
**************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <memory>
int main ()
{
int i = 0;
const int ci = 0;
volatile int vi = 0;
const volatile int cvi = 0;
std::uninitialized_copy (&i, &i, &i);
std::uninitialized_copy (&i, &i, &vi);
std::uninitialized_copy (&ci, &ci, &i);
std::uninitialized_copy (&ci, &ci, &vi);
std::uninitialized_copy (&vi, &vi, &i);
std::uninitialized_copy (&vi, &vi, &vi);
std::uninitialized_copy (&cvi, &cvi, &i);
std::uninitialized_copy (&cvi, &cvi, &vi);
}

View File

@@ -0,0 +1,105 @@
/************************************************************************
*
* 21.string.append.stdcxx-438.cpp - regression test for STDCXX-438
*
* https://issues.apache.org/jira/browse/STDCXX-438
*
* $Id: 21.string.append.stdcxx-438.cpp 641433 2008-03-26 17:39:28Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <iterator>
#include <new>
#include <string>
#ifndef _RWSTD_NO_REPLACEABLE_NEW_DELETE
// disabled for compilers that can't reliably replace the operators
void* operator new (std::size_t n) throw (std::bad_alloc)
{
void* const ptr = std::malloc (n + sizeof n);
std::memset (ptr, -1, n);
*(std::size_t*)ptr = n;
return (std::size_t*)ptr + 1;
}
void operator delete (void *ptr) throw ()
{
if (ptr) {
std::memset (ptr, -1, *((std::size_t*)ptr - 1));
std::free ((std::size_t*)ptr - 1);
}
}
#endif // _RWSTD_NO_REPLACEABLE_NEW_DELETE
struct InputIterator: std::iterator<std::input_iterator_tag, char>
{
const char *p_;
InputIterator (const char *p): p_ (p) { }
char operator* () const { return *p_; }
InputIterator& operator++ () { return ++p_, *this; }
InputIterator operator++ (int) {
return ++p_, InputIterator (p_ - 1);
}
bool operator== (const InputIterator &rhs) const { return p_ == rhs.p_; }
};
int main ()
{
const char s[] = "abc";
{
std::string str (s);
const char* p0 = s + 1;
const char* p1 = p0 + 1;
const InputIterator first (p0);
const InputIterator last (p1);
str.append (first, last);
assert ("abcb" == str);
}
{
std::string str (s);
const char* p0 = str.data () + 1;
const char* p1 = p0 + 1;
const InputIterator first (p0);
const InputIterator last (p1);
str.append (first, last);
assert ("abcb" == str);
}
return 0;
}

View File

@@ -0,0 +1,62 @@
/***********************************************************************
*
* 21.string.io.stdcxx-206.cpp - regression test for STDCXX-206
*
* http://issues.apache.org/jira/browse/STDCXX-206
*
* $Id: 21.string.io.stdcxx-206.cpp 590132 2007-10-30 16:01:33Z faridz $
*
***********************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
***********************************************************************/
#include <strstream>
#include <string>
#include <cassert>
void test (const std::string& str, const std::streamsize width)
{
char buf[10];
std::ostrstream os (buf, sizeof(buf));
os.width (width);
os.exceptions (std::ios_base::failbit | std::ios_base::badbit);
try {
os << str;
}
catch (std::ios_base::failure&) {
}
#ifndef _RWSTD_NO_EXT_KEEP_WIDTH_ON_FAILURE
assert (width == os.width ());
#else
assert (0 == os.width ());
#endif
}
int main ()
{
std::string str ("abcdefghijk");
test (str, 2);
test (str, str.size () + 2);
return 0;
}

View File

@@ -0,0 +1,54 @@
/***********************************************************************
*
* 21.string.io.stdcxx-250.cpp - regression test for STDCXX-250
*
* http://issues.apache.org/jira/browse/STDCXX-250
*
* $Id: 21.string.io.stdcxx-250.cpp 620105 2008-02-09 13:25:00Z faridz $
*
***********************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
***********************************************************************/
#include <cassert>
#include <istream>
#include <string>
int main ()
{
struct MyBuf : std::streambuf {
int_type underflow () {
static int i = 0;
// i == 0: sgect() invoked from sentry ctor
// i == 1: sgetc() invoked from operator>>()
// i == 2: sbumpc() invoked from operator>>()
return 1 < i++ ? throw i : 'x';
}
} buf;
std::istream is (&buf);
std::string s;
is >> s;
assert ("x" == s);
assert ((is.failbit | is.badbit) == is.rdstate ());
return 0;
}

View File

@@ -0,0 +1,45 @@
/************************************************************************
*
* 21.string.replace.stdcxx-175.cpp - test case from STDCXX-175 issue
*
* $Id: 21.string.replace.stdcxx-175.cpp 580483 2007-09-28 20:55:52Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <string>
#include <stdexcept>
int main (int argc, char* argv [])
{
std::string s (4095, 'a');
try
{
s.replace (0, 1, "a", s.max_size () + 1);
assert (!"Expect length error, got nothing");
}
catch (std::length_error& e)
{
}
return 0;
}

View File

@@ -0,0 +1,72 @@
/************************************************************************
*
* 21.string.stdcxx-162.cpp - regression test for STDCXX-162
*
* https://issues.apache.org/jira/browse/STDCXX-162
*
* $Id: 21.string.stdcxx-162.cpp 648752 2008-04-16 17:01:56Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <string>
#ifdef _RWSTD_POSIX_THREADS
# include <pthread.h>
# define MUTEX pthread_mutex_t
#elif _RWSTD_SOLARIS_THREADS
# include <thread.h>
# define MUTEX mutex_t
#endif // _RWSTD_POSIX_THREADS
int main ()
{
typedef std::char_traits<char> Traits;
typedef std::allocator<char> Allocator;
typedef __rw::__string_ref<char, Traits, Allocator> strref;
struct SmallRef {
int ref_count;
std::string::size_type capacity;
std::string::size_type size;
};
// verify that the reference-counted string body isn't bigger
// than the struct above
assert (sizeof (strref) <= sizeof (SmallRef));
#ifdef MUTEX
struct LargeRef {
MUTEX mutex;
int ref_count;
std::string::size_type capacity;
std::string::size_type size;
};
// verify that the reference-counted string body is smaller
// than the struct containing a full-blown mutex object above
assert (sizeof (strref) < sizeof (LargeRef));
#endif // MUTEX
return 0;
}

View File

@@ -0,0 +1,59 @@
/************************************************************************
*
* 21.string.stdcxx-231.cpp - test case from STDCXX-231 issue
*
* $Id$
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <string>
#include <sstream>
int main ()
{
std::string s (100, 's');
const std::string::size_type n = s.capacity ();
const std::string::const_pointer p = s.c_str ();
// verify getline(), clear(), erase() and replace() do not
// unnecessarily resize or reallocate the data buffer
std::istringstream is ("hello world");
std::getline (is, s);
assert (s.capacity () == n);
assert (s.c_str () == p);
s.clear ();
assert (s.capacity () == n);
assert (s.c_str () == p);
s.erase ();
assert (s.capacity () == n);
assert (s.c_str () == p);
s.replace (0, std::string::npos, "1", 0);
assert (s.capacity () == n);
assert (s.c_str () == p);
return 0;
}

View File

@@ -0,0 +1,60 @@
/************************************************************************
*
* 21.string.stdcxx-466.cpp - test case from STDCXX-466 issue
*
* $Id: 21.string.stdcxx-466.cpp 580483 2007-09-28 20:55:52Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <string>
int main (int argc, char* argv[])
{
std::string s ("efgh");
const std::string::size_type len = s.max_size () + 1;
#define TEST(expr) \
try { \
assert (expr); \
} \
catch (...) { \
assert (!"Unexpected exception was thrown"); \
} (void)0
const std::string::size_type npos = std::string::npos;
TEST (npos == s.find ("fg", 0, len));
TEST (npos == s.rfind ("fg", 0, len));
TEST (0 == s.find_first_of ("eh", 0, len));
TEST (3 == s.find_last_of ("eh", npos, len));
TEST (0 > s.compare (0, npos, "efgh", len));
TEST (0 > s.compare (0, npos, "ijkl", len));
TEST (0 < s.compare (0, npos, "abcd", len));
s.clear ();
TEST (npos == s.find_first_not_of ("eh", 0, len));
TEST (npos == s.find_last_not_of ("eh", npos, len));
return 0;
}

View File

@@ -0,0 +1,91 @@
/************************************************************************
*
* 22.locale.codecvt.stdcxx-435.cpp - regression test for STDCXX-435
*
* http://issues.apache.org/jira/browse/STDCXX-435
*
* $Id: 22.locale.codecvt.stdcxx-435.cpp 648752 2008-04-16 17:01:56Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <clocale>
#include <cwchar>
#include <locale>
int main ()
{
// multibyte locale
std::locale mbloc;
// names of some well-known multibyte locales
const char* const names[] = {
"EN_US.UTF-8", // AIX
"en_US.UTF-8", // AIX, Linux, Solaris
"en_US.utf8", // HP-UX
// starting with Vista, Windows follows RFC 4646 name format
// http://msdn2.microsoft.com/en-us/library/ms776260(VS.85).aspx
"hy-AM", // Win 2000
"as-IN", // Win Vista
"bn-IN", // Win XP SP2
"zh-HK",
"zh-CN",
0
};
// try to find the first multibyte locale on this system
for (unsigned i = 0; names [i]; ++i) {
if (std::setlocale (LC_ALL, names [i])) {
mbloc = std::locale (names [i]);
break;
}
}
// fall back on the "C" locale...
typedef std::codecvt<wchar_t, char, std::mbstate_t> MbCvt;
const MbCvt &cvt = std::use_facet<MbCvt>(mbloc);
// source and destination buffers
const char src[] = "abc";
wchar_t dst [2] = { L'\0', L'\1' };
const char* from_next;
wchar_t* to_next;
std::mbstate_t state = std::mbstate_t ();
// convert exactly one source character, expect exactly
// one wide character in the destination buffer
const std::codecvt_base::result res =
cvt.in (state,
src, src + 1, from_next,
dst, dst + 2, to_next);
assert (cvt.ok == res);
assert (1 == from_next - src);
assert (1 == to_next - dst);
assert ('a' == dst [0] && '\1' == dst [1]);
}

View File

@@ -0,0 +1,84 @@
/************************************************************************
*
* 22.locale.cons.stdcxx-485.cpp
*
* test exercising the thread safety of locale ctors
*
* $Id: 22.locale.cons.stdcxx-485.cpp 580483 2007-09-28 20:55:52Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <cstring>
#include <locale>
#include <rw_locale.h>
#include <driver.h>
static int
run_test (int, char**)
{
// obtain a NUL-separated list of installed locales
const char* const names = rw_locales ();
if (0 == names || '\0' == *names)
return 0;
// repeatedly create a large set of unique named locale objects
for (int j = 0; j != 2; ++j) {
std::locale locales [64];
std::size_t i = 0;
for (const char *pn = names; *pn; ++i, pn += std::strlen (pn) + 1) {
if (i == sizeof locales / sizeof *locales)
break;
locales [i] = std::locale (pn);
}
i = 0;
for (const char *pn = names; *pn; ++i, pn += std::strlen (pn) + 1) {
if (i == sizeof locales / sizeof *locales)
break;
rw_assert (std::has_facet<std::collate<char> >(locales [i]),
0, __LINE__,
"std::has_facet<std::collate<char> >(locales(#s))",
pn);
}
}
return 0;
}
int main (int argc, char* argv[])
{
return rw_test (argc, argv, __FILE__,
"lib.locale.cons",
"STDCXX-485",
run_test,
"",
(void*)0);
}

View File

@@ -0,0 +1,99 @@
/************************************************************************
*
* 22.locale.messages.stdcxx-508_542.cpp
*
* the regression test for STDCXX-508, STDCXX-542 issues
*
* $Id: 22.locale.messages.stdcxx-542.cpp 580483 2007-09-28 20:55:52Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cstdio>
#include <cassert>
#include <locale>
#include <rw_locale.h>
#include <driver.h>
#ifdef _MSC_VER
#include <crtdbg.h>
#endif
#ifdef _WIN32
# define CATALOG "test"
# define MSG_EXT ".rc"
# define CAT_EXT ".dll"
#else
# define CATALOG "./test"
# define MSG_EXT ".msg"
# define CAT_EXT ".cat"
#endif
static int run_test (int, char**)
{
const char * catalog =
"First set, first message\0\0"
"Second set, first message\0\0";
rw_create_catalog (CATALOG MSG_EXT, catalog);
typedef std::messages<char> messagesT;
const std::locale loc;
const messagesT& msgs =
std::use_facet<messagesT>(loc);
messagesT::catalog cats [4];
int i;
// test STDCXX-508
for (i = 0; i < sizeof (cats) / sizeof (*cats); ++i) {
cats [i] = msgs.open (CATALOG CAT_EXT, loc);
assert (-1 != cats [i]);
}
// test STDCXX-542
for (--i; i >= 0; --i)
msgs.close (cats [i]);
std::remove (CATALOG CAT_EXT);
return 0;
}
int main (int argc, char* argv[])
{
#ifdef _MSC_VER
// disable GUI window from abort()
_CrtSetReportMode (_CRT_ERROR, _CRTDBG_MODE_DEBUG);
#endif
return rw_test (argc, argv, __FILE__,
"lib.locale.messages",
"STDCXX-508;STDCXX-542",
run_test,
"",
(void*)0);
}

View File

@@ -0,0 +1,50 @@
/************************************************************************
*
* 22.locale.money.get.stdcxx-62.cpp - regression test for STDCXX-62
*
* http://issues.apache.org/jira/browse/STDCXX-62
*
* $Id: 22.locale.money.get.stdcxx-62.cpp 650350 2008-04-22 01:35:17Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <ios>
#include <locale>
int main ()
{
typedef std::money_get<char> MoneyGet;
const MoneyGet &mg = std::use_facet<MoneyGet>(std::locale::classic ());
std::ios io (0);
std::ios::iostate err = std::ios::goodbit;
long double x = 0;
// verify that the facet behavior is well-defined for empty stream
mg.get (std::istreambuf_iterator<char>(),
std::istreambuf_iterator<char>(),
false, io, err, x);
assert ((std::ios::eofbit | std::ios::failbit) == err);
}

View File

@@ -0,0 +1,65 @@
/************************************************************************
*
* 22.locale.num.put.stdcxx-2.cpp
*
* the regression test for STDCXX-2 issue
*
* $Id: 22.locale.num.put.stdcxx-2.cpp 637239 2008-03-14 20:09:38Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <cstddef>
#include <ios>
#include <string>
#include <sstream>
void test (std::streamsize prec)
{
const std::size_t len = 0 > prec ? 7 : (1 < prec ? prec + 1 : 2);
std::string exp (len, '0');
exp [1] = '.';
std::ostringstream strm;
strm.setf (strm.showpoint);
strm.precision (prec);
strm << 0.0f;
assert (exp == strm.str ());
strm.str ("");
strm << 0.0;
assert (exp == strm.str ());
strm.str ("");
strm << 0.0L;
assert (exp == strm.str ());
}
int main ()
{
test (-2);
test (0);
test (1);
test (5);
return 0;
}

View File

@@ -0,0 +1,84 @@
/************************************************************************
*
* 22.locale.stdcxx-554.cpp - the regression test for STDCXX-554 issue
*
* $Id: 22.locale.stdcxx-554.cpp 648752 2008-04-16 17:01:56Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cstring> // for memset()
#include <cassert> // for assert()
#include <locale> // for std::moneypunct, std::messages
enum { fill = '\xdc' };
template <class charT>
void test_moneypunct (charT)
{
typedef std::moneypunct <charT> PunctT;
// Use a pointer to properly align buffer for placment new.
union {
void* ptr;
char buf [sizeof (PunctT) + 1];
} u;
std::memset (u.buf, fill, sizeof (u.buf));
PunctT* p = new (u.buf) PunctT ();
assert (fill == u.buf [sizeof (PunctT)]);
p->~PunctT ();
}
template <class charT>
void test_messages (charT)
{
typedef std::messages <charT> MessagesT;
union {
void* ptr;
char buf [sizeof (MessagesT) + 1];
} u;
std::memset (u.buf, fill, sizeof (u.buf));
MessagesT* p = new (u.buf) MessagesT ();
assert (fill == u.buf [sizeof (MessagesT)]);
p->~MessagesT ();
}
int main (int, char* [])
{
test_moneypunct (char ());
test_messages (char ());
#ifndef _RWSTD_NO_WCHAR_T
test_moneypunct (wchar_t ());
test_messages (wchar_t ());
#endif
return 0;
}

View File

@@ -0,0 +1,70 @@
/************************************************************************
*
* 23.associative.stdcxx-16.cpp - regression test for STDCXX-16
* http://issues.apache.org/jira/browse/STDCXX-16
*
* $Id: 23.associative.stdcxx-16.cpp 580483 2007-09-28 20:55:52Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <set>
#include <map>
#include <cassert>
template <class T>
struct RuntimeCmp
{
enum cmp_mode {normal, reverse};
cmp_mode mode;
RuntimeCmp (cmp_mode m = normal) : mode (m) { }
bool operator() (const T& t1, const T& t2) const {
return mode == normal ? t1 < t2 : t2 < t1;
}
};
template <class T>
bool operator== (const RuntimeCmp <T>& lc, const RuntimeCmp <T>& rc) {
return lc.mode == rc.mode;
}
typedef std::set <int, RuntimeCmp <int> > IntSet;
typedef std::map <int, int, RuntimeCmp <int> > IntMap;
int main ()
{
RuntimeCmp <int> reverse_order (RuntimeCmp<int>::reverse);
IntSet set1;
IntSet set2 (reverse_order);
set1 = set2;
assert (set1.key_comp () == set2.key_comp ());
assert (set1.value_comp () == set2.value_comp ());
IntMap map1;
IntMap map2 (reverse_order);
map1 = map2;
assert (map1.key_comp () == map2.key_comp ());
return 0;
}

View File

@@ -0,0 +1,51 @@
/************************************************************************
*
* 23.bitset.cons.stdcxx-297.cpp - test case from STDCXX-297 issue
*
* $Id: 23.bitset.cons.stdcxx-297.cpp 601042 2007-12-04 19:07:45Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <new>
#include <bitset>
#include <string>
#include <cstddef>
#include <string.h>
int main ()
{
typedef std::bitset<128> BitSet;
const std::size_t size = sizeof (BitSet);
char buf [size + 4];
memset (buf, '\xff', sizeof (buf));
const std::basic_string<int> s;
BitSet* btest = new (buf) BitSet (s);
for (std::size_t i = size; i < sizeof (buf); ++i)
assert ('\xff' == buf [i]);
btest->~BitSet ();
return 0;
}

View File

@@ -0,0 +1,42 @@
/************************************************************************
*
* 23.deque.special.stdcxx-127.cpp - test case from STDCXX-127 issue
*
* $Id: 23.deque.special.stdcxx-127.cpp 550991 2007-06-26 23:58:07Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cstddef>
#include <deque>
struct A { char tmp [32]; };
int main ()
{
A a [32];
std::deque<A> lhs (a, a + 0);
std::deque<A> rhs (a, a + 1);
lhs.swap (rhs);
return 0;
}

View File

@@ -0,0 +1,118 @@
/************************************************************************
*
* 23.list.cons.stdcxx-268.cpp - test case from STDCXX-268 issue
*
* $Id: 23.list.cons.stdcxx-268.cpp 550991 2007-06-26 23:58:07Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <list>
#include <cassert>
static int throw_inx = -1;
class ListItem
{
public:
static int count_;
void test ()
{
if (throw_inx == count_)
throw count_;
++count_;
}
ListItem () { test (); }
ListItem (const ListItem&) { test (); }
~ListItem () { --count_; }
};
int ListItem::count_ = 0;
int main(int argc, char* argv[])
{
typedef std::list<ListItem> List;
ListItem items [20];
List lst (20);
bool thrown = false;
throw_inx = 10;
try {
ListItem::count_ = 0;
List test (20);
} catch (...) {
thrown = true;
}
assert (thrown);
assert (0 == ListItem::count_);
try {
thrown = false;
ListItem::count_ = 0;
List test (20, items [0]);
} catch (...) {
thrown = true;
}
assert (thrown);
assert (0 == ListItem::count_);
try {
thrown = false;
ListItem::count_ = 0;
List test (items, items + 20);
} catch (...) {
thrown = true;
}
assert (thrown);
assert (0 == ListItem::count_);
try {
thrown = false;
ListItem::count_ = 0;
List test (lst.begin (), lst.end ());
} catch (...) {
thrown = true;
}
assert (thrown);
assert (0 == ListItem::count_);
try {
thrown = false;
ListItem::count_ = 0;
List test (lst);
} catch (...) {
thrown = true;
}
assert (thrown);
assert (0 == ListItem::count_);
return 0;
}

View File

@@ -0,0 +1,93 @@
/************************************************************************
*
* 23.list.insert.stdcxx-331.cpp - test case from STDCXX-331 issue
*
* $Id: 23.list.insert.stdcxx-331.cpp 550991 2007-06-26 23:58:07Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <list>
#include <cassert>
static int throw_inx = -1;
class ListItem
{
public:
static int count_;
void test ()
{
if (throw_inx == count_)
throw count_;
++count_;
}
ListItem () { test (); }
ListItem (const ListItem&) { test (); }
~ListItem () { --count_; }
};
int ListItem::count_ = 0;
int main (int argc, char* argv[])
{
typedef std::list<ListItem> List;
ListItem items [20];
List lst (1);
bool thrown = false;
throw_inx = 10;
List::iterator it = lst.begin ();
ListItem & ref = *it;
try {
ListItem::count_ = 0;
lst.insert (it, 20, items [0]);
} catch (...) {
thrown = true;
}
assert (thrown);
assert (it == lst.begin ());
assert (&ref == &*lst.begin ());
assert (1 == lst.size ());
assert (0 == ListItem::count_);
try {
ListItem::count_ = 0;
lst.insert (it, items, items + 20);
} catch (...) {
thrown = true;
}
assert (thrown);
assert (it == lst.begin ());
assert (&ref == &*lst.begin ());
assert (1 == lst.size ());
assert (0 == ListItem::count_);
return 0;
}

View File

@@ -0,0 +1,66 @@
/************************************************************************
*
* 23.list.special.stdcxx-334.cpp - test case from STDCXX-334 issue
*
* $Id: 23.list.special.stdcxx-334.cpp 550991 2007-06-26 23:58:07Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <list>
#include <string>
#include <cassert>
class Alloc : public std::allocator <char>
{
};
bool operator == (Alloc a1, Alloc a2)
{
return false;
}
bool operator != (Alloc a1, Alloc a2)
{
return true;
}
int main(int argc, char* argv[])
{
const char src [] = "source string";
const char dst [] = "destination string";
typedef std::list <char, Alloc> List;
Alloc a1;
Alloc a2;
assert (!(a1 == a2));
List src_lst (src, src + sizeof (src) - 1, a1);
List dst_lst (dst, dst + sizeof (dst) - 1, a2);
src_lst.swap (dst_lst);
assert (std::string (src_lst.begin (), src_lst.end ()) == dst);
assert (std::string (dst_lst.begin (), dst_lst.end ()) == src);
return 0;
}

View File

@@ -0,0 +1,135 @@
/***************************************************************************
*
* 23.set.stdcxx-216.cpp - regression test for STDCXX-216
*
* $Id: 23.set.stdcxx-216.cpp 640522 2008-03-24 19:00:16Z vitek $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 1994-2008 Rogue Wave Software.
*
**************************************************************************/
#include <set>
#include <cassert>
struct Value
{
static const unsigned magic = 0x12344321;
Value (unsigned value = 0)
: value (value)
, valid (magic)
{
}
Value (const Value& key)
: value (key.value)
, valid (key.magic)
{
}
Value& operator= (const Value& rhs)
{
// assignment only valid from valid values
assert (rhs.is_valid ());
value = rhs.value;
valid = rhs.valid;
return *this;
}
~Value ()
{
// destruction only allowed for valid values
assert (is_valid ());
valid = 0;
}
bool is_valid () const
{
return valid == magic;
}
friend
bool operator< (const Value& lhs, const Value& rhs)
{
// comparing against an invalid value is forbidden
assert (lhs.is_valid ());
assert (rhs.is_valid ());
const int lhs_is_odd = lhs.value & 1;
const int rhs_is_odd = rhs.value & 1;
// sort all even numbers in ascending order
// followed by odd numbers in ascending order
return lhs_is_odd != rhs_is_odd
? lhs_is_odd < rhs_is_odd
: lhs.value < rhs.value;
}
unsigned value;
unsigned valid;
};
//#include <iostream>
//
//void dump (const std::set<Value>& s)
//{
// std::set<Value>::const_iterator b = s.begin ();
// std::set<Value>::const_iterator e = s.end ();
//
// for (/**/; b != e; ++b)
// std::cout << b->value << ' ';
// std::cout << std::endl;
//}
int main ()
{
// insert at begin
{
std::set<Value> s;
std::set<Value>::iterator i (s.begin ());
for (unsigned n = 0; n < 10; ++n)
s.insert (i, n);
}
// insert after last
{
std::set<Value> s;
std::set<Value>::iterator i (s.end ());
for (unsigned n = 0; n < 10; ++n)
i = s.insert (i, n);
}
// insert at end
{
std::set<Value> s;
std::set<Value>::iterator i (s.end ());
for (unsigned n = 0; n < 10; ++n)
s.insert (i, n);
}
return 0;
}

View File

@@ -0,0 +1,59 @@
/************************************************************************
*
* 23.vector.bool.stdcxx-235.cpp - regression test for STDCXX-235
*
* https://issues.apache.org/jira/browse/STDCXX-235
*
* $Id: 23.vector.bool.stdcxx-235.cpp 588739 2007-10-26 18:41:14Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <vector>
int main ()
{
std::vector<bool> v;
typedef std::vector<bool>::const_iterator const_iterator;
typedef std::vector<bool>::iterator iterator;
const const_iterator cbegin = v.begin ();
const iterator begin = v.begin ();
assert (cbegin == begin);
assert (begin == cbegin);
assert (!(cbegin != begin));
assert (!(begin != cbegin));
assert (cbegin <= begin);
assert (begin <= cbegin);
assert (cbegin >= begin);
assert (begin >= cbegin);
assert (!(cbegin < begin));
assert (!(begin < cbegin));
assert (!(cbegin > begin));
assert (!(begin > cbegin));
}

View File

@@ -0,0 +1,72 @@
/************************************************************************
*
* 23.vector.stdcxx-611.cpp - regression test for STDCXX-611
*
* https://issues.apache.org/jira/browse/STDCXX-611
*
* $Id: 23.vector.stdcxx-611.cpp 592996 2007-11-08 01:55:18Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <vector> // for vector
struct S
{
void operator& () const {};
};
void test ()
{
const S s [3] = { S (), S (), S () };
std::vector<S> v;
v.assign (1, s [0]);
v.assign (s, s+3);
v.at (0);
v.back ();
v.begin ();
v.capacity ();
v.empty ();
v.end ();
v.front ();
v.insert (v.begin (), s [0]);
v.insert (v.begin (), s, s+3);
v.insert (v.begin (), 2, s [0]);
v.erase (v.begin ());
v.erase (v.begin (), v.end ());
v.max_size ();
v.pop_back ();
v.push_back (s[0]);
v.rbegin ();
v.rend ();
v.reserve (10);
v.resize (10);
v.size ();
std::vector<S>().swap (v);
}
int main ()
{
// compile-time only test
return 0;
}

View File

@@ -0,0 +1,42 @@
/***********************************************************************
*
* 24.istream.iterator.cons.stdcxx-645.cpp
* regression test for STDCXX-645:
* http://issues.apache.org/jira/browse/STDCXX-645
*
* $Id: 24.istream.iterator.cons.stdcxx-645.cpp 648752 2008-04-16 17:01:56Z faridz $
*
***********************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
***********************************************************************/
#include <assert.h>
#include <iterator>
#include <sstream>
int main ()
{
std::istringstream a ("1");
std::istream_iterator<int> i (a);
std::istringstream b ("2");
std::istream_iterator<int> j (b);
assert (!(i == j));
}

View File

@@ -0,0 +1,49 @@
/***********************************************************************
*
* 24.istream.iterator.ops.stdcxx-321.cpp: regression test for STDCXX-321
*
* http://issues.apache.org/jira/browse/STDCXX-321
*
* $Id: 24.istream.iterator.ops.stdcxx-321.cpp 648752 2008-04-16 17:01:56Z faridz $
*
***********************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
***********************************************************************/
#include <cassert>
#include <iterator>
// no iostream header should be #included in this test
#ifdef _RWSTD_ISTREAM_INCLUDED
# error "<istream> unexpectedly #included"
#endif // _RWSTD_ISTREAM_INCLUDED
int main ()
{
const std::istream_iterator<char, char> it;
const std::istream_iterator<char, char> eos;
// istream_iterator equality operator should compile
// when the <istream> header isn't #included (and
// the iterator should compare equal to the end of
// stream iterator)
assert (it == eos);
return 0;
}

View File

@@ -0,0 +1,47 @@
/***************************************************************************
*
* 24.operations.stdcxx-234 - regression test for STDCXX-234
* http://issues.apache.org/jira/browse/STDCXX-234
*
* $Id: 24.operations.stdcxx-234.cpp 580483 2007-09-28 20:55:52Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 2007 Rogue Wave Software, Inc.
*
**************************************************************************/
#include <iterator>
struct X: std::iterator<std::random_access_iterator_tag, int> { };
namespace std {
// specialize the std::distance() function template of a user-defined
// iterator type to verify that the signature of the primary template
// is the same as the one of the specialization
template <> std::iterator_traits<X>::difference_type
distance<X> (X, X) { return 0; }
} // namespace std
int main ()
{
return std::distance (X (), X ());
}

View File

@@ -0,0 +1,42 @@
/************************************************************************
*
* 26.valarray.binary.stdcxx-237.cpp - regression test for STDCXX-237
*
* http://issues.apache.org/jira/browse/STDCXX-237
*
* $Id: 26.valarray.binary.stdcxx-237.cpp 580483 2007-09-28 20:55:52Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <valarray>
int main()
{
std::valarray<int> ia;
std::gslice gs;
std::valarray<int> res = std::operator%<int>(ia [gs], ia [gs]);
assert (0 == res.size ());
return 0;
}

View File

@@ -0,0 +1,69 @@
/************************************************************************
*
* 26.valarray.members.stdcxx-313.cpp - regression test for STDCXX-313
*
* http://issues.apache.org/jira/browse/STDCXX-313
*
* $Id: 26.valarray.members.stdcxx-313.cpp 590132 2007-10-30 16:01:33Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <new>
#include <valarray>
void* operator new (std::size_t s) throw (std::bad_alloc)
{
return std::memset (std::malloc (s), 0x55, s);
}
void operator delete (void *ptr) throw ()
{
std::free (ptr);
}
struct S {
const S* const self;
S (): self (this) { }
S (const S &s): self (this) { assert (&s == s.self); }
~S () { assert (this == self); }
S& operator= (const S &s) {
assert (this == self && &s == s.self);
return *this;
}
};
S foo (S s) { return s; }
S bar (const S &s) { return s; }
int main ()
{
const std::valarray<S> a (2);
a.apply (foo);
a.apply (bar);
}

View File

@@ -0,0 +1,41 @@
/************************************************************************
*
* 26.valarray.members.stdcxx-318.cpp - regression test for STDCXX-318
*
* http://issues.apache.org/jira/browse/STDCXX-318
*
* $Id: 26.valarray.members.stdcxx-318.cpp 590132 2007-10-30 16:01:33Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <valarray>
int main ()
{
const std::valarray<int> a;
a.cshift (1);
assert (0 == a.size ());
return 0;
}

View File

@@ -0,0 +1,44 @@
/************************************************************************
*
* 26.valarray.sub.stdcxx-224.cpp - regression test for STDCXX-224
* http://issues.apache.org/jira/browse/STDCXX-224
*
* $Id: 26.valarray.sub.stdcxx-224.cpp 590132 2007-10-30 16:01:33Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <cstddef>
#include <valarray>
int main ()
{
const int vals[] = { 1, 0 };
const std::size_t N = sizeof vals / sizeof *vals;
const std::valarray<int> p (vals, N);
assert (N == p.size ());
const std::valarray<int> r = p [std::slice (0, 0, 1)];
assert (0 == r.size ());
}

View File

@@ -0,0 +1,51 @@
/************************************************************************
*
* 26.valarray.sub.stdcxx-309.cpp - regression test for STDCXX-309
*
* https://issues.apache.org/jira/browse/STDCXX-309
*
* $Id: 26.valarray.sub.stdcxx-309.cpp 580483 2007-09-28 20:55:52Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <cstddef>
#include <valarray>
int main ()
{
const int a[] = { 1, 2, 3, 4, 5, 6 };
const std::valarray<int> v (a, sizeof a / sizeof *a);
const std::size_t start = 5;
std::valarray<std::size_t> length (1, 1);
std::valarray<std::size_t> stride (1, 1);
const std::gslice gsl (start, length, stride);
for (int i = 0; i != 2; ++i) {
const std::valarray<int> vsl = v [gsl];
assert (a [start] == vsl [0]);
}
return 0;
}

View File

@@ -0,0 +1,41 @@
/************************************************************************
*
* 26.valarray.sub.stdcxx-448.cpp - regression test for STDCXX-448
* https://issues.apache.org/jira/browse/STDCXX-448
*
* $Id: 26.valarray.sub.stdcxx-448.cpp 550991 2007-06-26 23:58:07Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <valarray>
int main ()
{
const std::valarray<double> dval;
std::valarray<double> result (dval [std::gslice ()]);
assert (result.size () == 0);
return 0;
}

View File

@@ -0,0 +1,102 @@
/************************************************************************
*
* 26.valarray.transcend.stdcxx-315.cpp - regression test for STDCXX-315
*
* http://issues.apache.org/jira/browse/STDCXX-315
*
* $Id: 26.valarray.transcend.stdcxx-315.cpp 589882 2007-10-29 22:00:32Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <new>
#include <valarray>
void* operator new (std::size_t s) throw (std::bad_alloc)
{
return std::memset (std::malloc (s), 0x55, s);
}
bool pass = true;
struct S {
const S* const self;
S (): self (this) { }
S (const S &s): self (this) { pass = pass && &s == s.self; }
S (double): self (this) { }
~S () { pass = pass && this == self; }
operator double () const { pass = pass && this == self; return 1.0; }
void operator=(const S &s) {
pass = pass && &s == s.self && this == self;
}
S operator- () const { pass = pass && this == self; return *this; }
bool operator< (const S &s) const {
pass = pass && &s == s.self && this == self;
return false;
}
};
int main ()
{
const S s;
const std::valarray<S> a (2);
int nfails = 0;
#define TEST(fun, args) \
pass = true; \
fun args; \
if (!pass) { \
std::fprintf (stderr, "std::%s uses uninitialized storage\n", \
#fun); \
++nfails; \
} (void)0
TEST (abs, (a));
TEST (acos, (a));
TEST (asin, (a));
TEST (atan, (a));
TEST (atan2, (a, a));
TEST (atan2, (a, s));
TEST (atan2, (s, a));
TEST (cos, (a));
TEST (cosh, (a));
TEST (exp, (a));
TEST (log, (a));
TEST (log10, (a));
TEST (pow, (a, a));
TEST (pow, (a, s));
TEST (pow, (s, a));
TEST (sin, (a));
TEST (sinh, (a));
TEST (sqrt, (a));
TEST (tan, (a));
TEST (tanh, (a));
assert (0 == nfails);
return 0;
}

View File

@@ -0,0 +1,69 @@
/************************************************************************
*
* 26.valarray.unary.stdcxx-314.cpp - regression test for STDCXX-314
*
* http://issues.apache.org/jira/browse/STDCXX-314
*
* $Id: 26.valarray.unary.stdcxx-314.cpp 590132 2007-10-30 16:01:33Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <new>
#include <valarray>
void* operator new (std::size_t s) throw (std::bad_alloc)
{
return std::memset (std::malloc (s), 0x55, s);
}
void operator delete (void *ptr) throw ()
{
std::free (ptr);
}
struct S {
const S* const self;
S (): self (this) { }
S (const S &s): self (this) { assert (&s == s.self); }
~S () { assert (this == self); }
S operator+ () const { assert (this == self); return *this; }
S operator- () const { assert (this == self); return *this; }
S operator~ () const { assert (this == self); return *this; }
bool operator! () const { assert (this == self); return false; }
void operator= (const S &s) { assert (this == self && &s == s.self); }
};
int main ()
{
const std::valarray<S> a (2);
+a;
-a;
~a;
!a;
}

View File

@@ -0,0 +1,78 @@
/**************************************************************************
*
* 27.basic.ios.copyfmt.stdcxx-766.cpp - regression test for STDCXX-766
*
* http://issues.apache.org/jira/browse/STDCXX-766
*
* $Id: 27.basic.ios.copyfmt.stdcxx-766.cpp 648752 2008-04-16 17:01:56Z faridz $
*
**************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <ios>
#include <iosfwd>
#include <locale>
#include <ostream>
int main ()
{
struct: std::streambuf { } xsb, ysb;
std::ostream xstrm (0);
std::ostream ystrm (0);
std::ios x (&xsb);
std::ios y (&ysb);
x.tie (&xstrm);
const std::ios::iostate x_rdstate = x.rdstate ();
const std::streambuf* const x_rdbuf = x.rdbuf ();
const std::locale loc =
std::locale (std::locale::classic (), new std::numpunct<char>());
// set up y to be different from x
y.tie (&ystrm);
y.exceptions (y.eofbit);
y.setf (y.boolalpha);
y.precision (x.precision () + 1);
y.width (x.width () + 1);
y.fill (x.fill () + 1);
y.imbue (loc);
// verify test preconditions
assert (x.tie () != y.tie ());
assert (x.getloc () != y.getloc ());
x.copyfmt (y);
// verify copyfmt() postconditions
assert (x.rdbuf () == x_rdbuf);
assert (x.tie () == y.tie ());
assert (x.rdstate () == x_rdstate);
assert (x.exceptions () == y.exceptions ());
assert (x.flags () == y.flags ());
assert (x.precision () == y.precision ());
assert (x.width () == y.width ());
assert (x.fill () == y.fill ());
assert (x.getloc () == y.getloc ());
}

View File

@@ -0,0 +1,90 @@
/************************************************************************
*
* 27.basic.ios.tie.stdcxx-804 - regression test for STDCXX-804
*
* http://issues.apache.org/jira/browse/STDCXX-804
*
* $Id: 27.basic.ios.tie.stdcxx-804.cpp 648752 2008-04-16 17:01:56Z faridz $
*
************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 2008 Rogue Wave Software, Inc.
*
**************************************************************************/
#include <cassert>
#include <cstddef>
#include <cstdio>
#include <sstream>
// tie the first n streams together in a circular list
void tie (std::ostringstream *ps, std::size_t n)
{
for (std::size_t i = 0; i + 1 < n; ++i)
ps [i].tie (ps + i + 1);
if (n) {
std::ostream *plast = ps + (n - 1);
plast->tie (ps);
}
}
// detect a cycle in a list of tied streams
bool is_cycle (const std::ostream *ps)
{
if (0 == ps)
return false;
const std::ostream *p0, *p1;
for (p0 = ps, p1 = ps->tie (); p0 && p1;
p0 = p0->tie (), p1 = p1->tie () ? p1->tie ()->tie () : 0)
if (p0 == p1 || p0->rdbuf () == p1->rdbuf ())
return true;
return false;
}
int main ()
{
std::ostringstream strm [32];
const std::size_t N = sizeof strm / sizeof *strm;
for (std::size_t i = 0; i != N; ++i) {
// tie the first i streams together in a circular list
tie (strm, i);
assert (0 == i || is_cycle (strm));
for (std::size_t j = 0; j != i; ++j) {
// make sure formatted and unformatted output for
// each of the tied streams works without getting
// into a deadlock or into infinite recursion
strm [j] << j;
strm [j].flush ();
assert (strm [j].good ());
}
}
return 0;
}

View File

@@ -0,0 +1,205 @@
/************************************************************************
*
* 27.cstdio.stdcxx-195.cpp - regression test for STDCXX-195
*
* $Id: 27.cstdio.stdcxx-195.cpp 609466 2008-01-06 23:18:56Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cstdio>
#ifdef _RWSTD_STRICT_ANSI
# ifdef fpos_t
# error "fpos_t #defined"
# endif
# ifdef remove
# error "remove #defined"
# endif
# ifdef rename
# error "rename #defined"
# endif
# ifdef tmpfile
# error "tmpfile #defined"
# endif
# ifdef tmpnam
# error "tmpnam #defined"
# endif
# ifdef fclose
# error "fclose #defined"
# endif
# ifdef fflush
# error "fflush #defined"
# endif
# ifdef fopen
# error "fopen #defined"
# endif
# ifdef freopen
# error "freopen #defined"
# endif
# ifdef setbuf
# error "setbuf #defined"
# endif
# ifdef setvbuf
# error "setvbuf #defined"
# endif
# ifdef fprintf
# error "fprintf #defined"
# endif
# ifdef fscanf
# error "fscanf #defined"
# endif
# ifdef printf
# error "printf #defined"
# endif
# ifdef scanf
# error "scanf #defined"
# endif
# ifdef sprintf
# error "sprintf #defined"
# endif
# ifdef sscanf
# error "sscanf #defined"
# endif
# ifdef vfprintf
# error "vfprintf #defined"
# endif
# ifdef vprintf
# error "vprintf #defined"
# endif
# ifdef vsprintf
# error "vsprintf #defined"
# endif
# ifdef fgetc
# error "fgetc #defined"
# endif
# ifdef fgets
# error "fgets #defined"
# endif
# ifdef fputc
# error "fputc #defined"
# endif
# ifdef fputs
# error "fputs #defined"
# endif
# ifdef getc
# error "getc #defined"
# endif
# ifdef getchar
# error "getchar #defined"
# endif
# ifdef gets
# error "gets #defined"
# endif
# ifdef putc
# error "putc #defined"
# endif
# ifdef putchar
# error "putchar #defined"
# endif
# ifdef puts
# error "puts #defined"
# endif
# ifdef ungetc
# error "ungetc #defined"
# endif
# ifdef fread
# error "fread #defined"
# endif
# ifdef fwrite
# error "fwrite #defined"
# endif
# ifdef fgetpos
# error "fgetpos #defined"
# endif
# ifdef fseek
# error "fseek #defined"
# endif
# ifdef fsetpos
# error "fsetpos #defined"
# endif
# ifdef ftell
# error "ftell #defined"
# endif
# ifdef rewind
# error "rewind #defined"
# endif
# ifdef clearerr
# error "clearerr #defined"
# endif
# ifdef feof
# error "feof #defined"
# endif
# ifdef ferror
# error "ferror #defined"
# endif
# ifdef perror
# error "perror #defined"
# endif
#endif // _RWSTD_STRICT_ANSI
int main ()
{
return 0;
}

View File

@@ -0,0 +1,173 @@
/***********************************************************************
*
* 27.filebuf.members.stdcxx-308.cpp - regression test for STDCXX-308
* http://issues.apache.org/jira/browse/STDCXX-308
*
* $Id: 27.filebuf.members.stdcxx-308.cpp 648752 2008-04-16 17:01:56Z faridz $
*
***********************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
* Copyright 2008 Rogue Wave Software, Inc.
*
***********************************************************************
*
* Test description:
* Sets a maxinum file size limit, forces filebuf to exceed the limit,
* causing the class dtor to fail to flush the excess data. Verifies
* that the dtor closes the associated file descriptor regardless of
* the failure as required by the resolution of LWG issue 622:
* http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-active.html#622
*
***********************************************************************/
#include <cassert> // for assert()
#include <cstdio> // for remove(), size_t
#include <fstream> // for filebuf
#if !defined (_WIN32) || defined (__CYGWIN__)
# include <sys/resource.h> // for getrlimit(), rlim_t
# include <unistd.h> // for close(), write(), ssize_t
#endif // !_WIN32 || __CYGWIN__
int write_bytes (const char *fname, std::size_t nbytes)
{
std::filebuf fb;
if ( 0 == fb.pubsetbuf (0, nbytes + 1)
|| 0 == fb.open (fname, std::ios::out))
return -1;
#if defined (_RWSTD_VER) && !defined (_RWSTD_NO_EXT_FILEBUF)
// use the filebuf::fd() extension to get the filebuf's
// associated file descriptor
const int fd = fb.fd ();
#else // if defined (RWSTD_NO_EXT_FILEBUF)
// assume fd is the next available file descriptor after
// STDIN_FILENO, _FILENO_STDOUT, and STDERR_FILENO
const int fd = 3;
#endif // RWSTD_NO_EXT_FILEBUF
if (0 < fd) {
// fill up the filebuf's character buffer without
// overflowing
for (std::size_t i = 0; i != nbytes; ++i)
fb.sputc ('*');
}
// have filebuf dtor try to flush the object's character
// buffer and expect it to fail (and flush out only the
// number specified by RLIMIT_FSIZE)
// return the file descriptor to the caller so that it can
// verify that it has been closed
return fd;
}
int main ()
{
#if !defined (_WIN32) || defined (__CYGWIN__)
const char fname[] = "testfile.text";
std::remove (fname);
rlimit rl;
int status;
// retrieve the current file size limits
status = getrlimit (RLIMIT_FSIZE, &rl);
if (status) {
std::perror ("getrlimit(RLIMIT_FSIZE, ...)");
return 1;
}
// uncomment for debugging
// std::printf ("file size limits = %ld, %ld\n",
// long (rl.rlim_cur), long (rl.rlim_max));
const rlim_t rlim_cur_saved = rl.rlim_cur;
rl.rlim_cur = 32;
// set a new file size limit
status = setrlimit (RLIMIT_FSIZE, &rl);
if (status) {
std::perror ("setrlimit(RLIMIT_FSIZE, ...)");
return 1;
}
// uncomment for debugging
// status = getrlimit (RLIMIT_FSIZE, &rl);
// if (status) {
// std::perror ("getrlimit(RLIMIT_FSIZE, ...)");
// return 1;
// }
// std::printf ("file size limits = %ld, %ld\n",
// long (rl.rlim_cur), long (rl.rlim_max));
// try to write more bytes than the current soft limit using
// filebuf, expecting the class dtor to fail but close the
// associated file descriptor
const int fd = write_bytes (fname, std::size_t (rl.rlim_cur + 1));
if (fd < 0) {
std::perror ("filebuf::~filebuf()");
std::remove (fname);
return 1;
}
// restore the previous soft limit
rl.rlim_cur = rlim_cur_saved;
status = setrlimit (RLIMIT_FSIZE, &rl);
if (status) {
std::perror ("setrlimit(RLIMIT_FSIZE, ...)");
close (fd);
std::remove (fname);
return 1;
}
// try to write to the filebuf's file descriptor, expecting
// the write() to fail
const ssize_t nwrote = write (fd, "<", 1);
assert (-1 == nwrote);
// close file descriptor before removing the file (it's okay
// if the call fails because the fd has already been closed)
close (fd);
std::remove (fname);
#else // Windows
// See about implementing using SetFileValidData():
// http://msdn.microsoft.com/en-us/library/aa365544(VS.85).aspx
#endif // !_WIN32 || __CYGWIN__
return 0;
}

View File

@@ -0,0 +1,48 @@
/************************************************************************
*
* 27.filebuf.virtuals.stdcxx-522.cpp - regression test for STDCXX-522
*
* http://issues.apache.org/jira/browse/STDCXX-522
*
* $Id: 27.filebuf.virtuals.stdcxx-522.cpp 620105 2008-02-09 13:25:00Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <fstream>
#include <ios>
int main ()
{
struct MyBuf : std::filebuf {
int_type overflow (int_type c) {
return std::filebuf::overflow (c);
}
} buf;
buf.open ("file", std::ios::out);
buf.pubsetbuf (0, 0);
buf.overflow (std::filebuf::traits_type::eof ());
buf.close ();
std::ifstream in ("file");
assert (std::istream::traits_type::eof () == in.get ());
}

View File

@@ -0,0 +1,71 @@
/************************************************************************
*
* 27.ostream.unformatted.stdcxx-626.cpp - regression test for STDCXX-626
*
* http://issues.apache.org/jira/browse/STDCXX-626
*
* $Id: 27.ostream.unformatted.stdcxx-626.cpp 612563 2008-01-16 20:31:30Z sebor $
*
************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
************************************************************************/
#include <cassert>
#include <ostream>
int sync_calls;
struct MyBuf: std::streambuf
{
virtual int sync () {
++sync_calls;
return -1;
}
};
int main ()
{
MyBuf buf;
std::ostream os (&buf);
// verify that ostream::flush() doesn't call streambuf::sync()
// when the state of the stream isn't good
os.setstate (os.badbit);
os.flush ();
assert (0 == sync_calls);
os.setstate (os.eofbit);
os.flush ();
assert (0 == sync_calls);
os.setstate (os.failbit);
os.flush ();
assert (0 == sync_calls);
return 0;
}

View File

@@ -0,0 +1,60 @@
/************************************************************************
*
* 27.streambuf.imbue.stdcxx-307.cpp - test case from STDCXX-307 issue
*
* $Id: 27.streambuf.imbue.stdcxx-307.cpp 597670 2007-11-23 14:11:16Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <locale>
#include <streambuf>
struct MyFacet: std::locale::facet
{
static std::locale::id id;
};
std::locale::id MyFacet::id;
int main ()
{
struct MyBuf: std::streambuf {
void imbue (const std::locale &loc) {
std::streambuf::imbue (loc);
}
} buf;
const std::locale loc (buf.getloc (), new MyFacet);
assert (_STD_HAS_FACET (MyFacet, loc));
assert (!_STD_HAS_FACET (MyFacet, buf.getloc ()));
buf.imbue (loc);
assert (!_STD_HAS_FACET (MyFacet, buf.getloc ()));
buf.pubimbue (loc);
assert (_STD_HAS_FACET (MyFacet, buf.getloc ()));
return 0;
}

View File

@@ -0,0 +1,64 @@
/************************************************************************
*
* 27.stringbuf.members.stdcxx-427.cpp - test case from STDCXX-427 issue
*
* $Id: 27.stringbuf.members.stdcxx-427.cpp 550991 2007-06-26 23:58:07Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <cassert>
#include <cstdio>
#include <sstream>
int main ()
{
struct Buf: std::stringbuf {
Buf (std::string s, std::ios::openmode m)
: std::stringbuf (s, m) { }
void setget (int beg, int cur, int end) {
setg (eback () + beg, eback () + cur, eback () + end);
}
void setput (int beg, int cur, int end) {
setp (pbase () + beg, pbase () + end);
pbump (cur);
}
};
{
Buf buf ("abcde", std::ios::in);
buf.setget (1, 2, 4);
std::printf ("%s\n", buf.str ().c_str ());
assert ("bcd" == buf.str ());
}
{
Buf buf ("abcde", std::ios::out);
buf.setput (1, 2, 4);
std::printf ("%s\n", buf.str ().c_str ());
assert ("bcde" == buf.str ());
}
{
Buf buf ("abcde", std::ios::openmode ());
std::printf ("%s\n", buf.str ().c_str ());
assert ("" == buf.str ());
}
}

View File

@@ -0,0 +1,45 @@
/************************************************************************
*
* 27.stringbuf.overflow.stdcxx-795.cpp - test case from STDCXX-795 issue
*
* $Id: 27.stringbuf.overflow.stdcxx-795.cpp 648752 2008-04-16 17:01:56Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <sstream> // for ostringstream
#include <string> // for string
#include <cassert> // for assert()
#include <cstddef> // for size_t
int main ()
{
std::ostringstream strm;
std::string s;
for (std::size_t i = 1; i <= 1024; ++i) {
const char c = char (i);
strm << c;
s.push_back (c);
assert (strm.str () == s);
}
return 0;
}

View File

@@ -0,0 +1,58 @@
/************************************************************************
*
* 27.stringbuf.str.stdcxx-514.cpp - test case from STDCXX-514 issue
*
* $Id: 27.stringbuf.str.stdcxx-514.cpp 580483 2007-09-28 20:55:52Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <sstream> // for stringbuf
#include <memory> // for allocator
#include <cassert> // for assert()
char extbuf [3];
struct MyAlloc : std::allocator <char>
{
pointer allocate (size_type __n, std::allocator<void>::const_pointer = 0) {
return new char [__n];
}
void deallocate (pointer __p, size_type)
{
assert (extbuf != __p);
delete [] __p;
}
};
int main ()
{
std::basic_stringbuf <char, std::char_traits <char>, MyAlloc> sbuf;
sbuf.pubsetbuf (extbuf, sizeof (extbuf));
const char* str = "abcdef";
sbuf.str (str);
assert (sbuf.str () == str);
return 0;
}

View File

@@ -0,0 +1,46 @@
/************************************************************************
*
* 27.stringbuf.xsputn.stdcxx-515.cpp - test case from STDCXX-515 issue
*
* $Id: 27.stringbuf.xsputn.stdcxx-515.cpp 589892 2007-10-29 22:27:47Z sebor $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <sstream> // for stringstream
#include <string> // for string
#include <cassert> // for assert()
#include <cstddef> // for size_t
int main ()
{
for (std::size_t i = 1; i <= 1024; ++i) {
std::stringstream strm;
std::string s (i, 'a');
strm << s;
strm.seekp (-1, std::ios::cur);
s.erase (0, 1);
strm << "bc";
s.append ("bc");
assert (strm.str () == s);
}
return 0;
}

View File

@@ -0,0 +1,54 @@
/************************************************************************
*
* 27.stringbuf.xsputn.stdcxx-576.cpp - test case from STDCXX-576 issue
*
* $Id: 27.stringbuf.xsputn.stdcxx-576.cpp 590132 2007-10-30 16:01:33Z faridz $
*
***************************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you 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
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*
**************************************************************************/
#include <sstream> // for stringbuf
#include <string> // for string
#include <cassert> // for assert()
struct PubBuf: std::stringbuf
{
char* Pbase () const { return this->pbase (); }
};
int main ()
{
// 512 is the default buffer size of the basic_stringbuf
std::string s (512, 'a');
std::stringbuf sbuf (s);
PubBuf& buf = (PubBuf&)sbuf;
std::streamsize res = buf.sputn (buf.Pbase (), 128);
s.append (s.begin (), s.begin () + 128);
const std::string& str = buf.str ();
assert (res == 128);
assert (str.size () == s.size ());
assert (str == s);
return 0;
}