From stdcxx-commits-return-1154-apmail-incubator-stdcxx-commits-archive=incubator.apache.org@incubator.apache.org Fri Mar 02 21:16:47 2007 Return-Path: Delivered-To: apmail-incubator-stdcxx-commits-archive@www.apache.org Received: (qmail 64258 invoked from network); 2 Mar 2007 21:16:46 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Mar 2007 21:16:46 -0000 Received: (qmail 62125 invoked by uid 500); 2 Mar 2007 21:16:55 -0000 Delivered-To: apmail-incubator-stdcxx-commits-archive@incubator.apache.org Received: (qmail 62108 invoked by uid 500); 2 Mar 2007 21:16:55 -0000 Mailing-List: contact stdcxx-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: stdcxx-dev@incubator.apache.org Delivered-To: mailing list stdcxx-commits@incubator.apache.org Received: (qmail 62097 invoked by uid 99); 2 Mar 2007 21:16:55 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Mar 2007 13:16:55 -0800 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Mar 2007 13:16:45 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id AD1EA1A981F; Fri, 2 Mar 2007 13:16:25 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r513959 - /incubator/stdcxx/trunk/tests/self/0.outputiter.cpp Date: Fri, 02 Mar 2007 21:16:25 -0000 To: stdcxx-commits@incubator.apache.org From: sebor@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070302211625.AD1EA1A981F@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: sebor Date: Fri Mar 2 13:16:24 2007 New Revision: 513959 URL: http://svn.apache.org/viewvc?view=rev&rev=513959 Log: 2007-03-02 Martin Sebor * 0.outputiter.cpp: New test exercising the helper class template OutputIter. Added: incubator/stdcxx/trunk/tests/self/0.outputiter.cpp (with props) Added: incubator/stdcxx/trunk/tests/self/0.outputiter.cpp URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/tests/self/0.outputiter.cpp?view=auto&rev=513959 ============================================================================== --- incubator/stdcxx/trunk/tests/self/0.outputiter.cpp (added) +++ incubator/stdcxx/trunk/tests/self/0.outputiter.cpp Fri Mar 2 13:16:24 2007 @@ -0,0 +1,333 @@ +/************************************************************************ + * + * 0.outputiter.cpp - test exercising the OutputIter class template + * + * $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. + * + * Copyright 1994-2005 Rogue Wave Software. + * + **************************************************************************/ + +#include +#include +#include + +#include // for OutputIter +#include // for UserClass +#include // for rw_test(), ... + +/***********************************************************************/ + +int exit_status /* = 0 */; + +extern "C" { + +int line; +int fail; + +jmp_buf env; + +void handle_ABRT (int) +{ + fail = 0; + + longjmp (env, 1); +} + +} + +#define FAIL(code) \ + fail = line = __LINE__; \ + signal (SIGABRT, handle_ABRT); \ + if (0 == setjmp (env)) { \ + code; \ + exit_status = 1; \ + rw_assert (0, 0, line, "expected assertion"); \ + } \ + else \ + (void)0 + +#define PASS(code) \ + fail = -1; line = __LINE__; \ + signal (SIGABRT, handle_ABRT); \ + if (0 == setjmp (env)) \ + code; \ + else if (fail != line) { \ + exit_status = 1; \ + rw_assert (0, 0, line, "unexpected assertion"); \ + } (void)0 + +/***********************************************************************/ + +static void +test_1 () +{ + UserClass *x = UserClass::from_char ("abcdef"); + UserClass *y = UserClass::from_char ("ABCDEF"); + + // use `out' as the last argument to make_iter() (as opposed + // to, say, OutputIter()) since Output Iterators + // are not required to be copy-constructible + OutputIter out = make_iter (x + 0, x + 0, x + 6, out); + + PASS (*out++ = y [0]); + PASS (*out++ = y [1]); + PASS (*out++ = y [2]); + PASS (*out++ = y [3]); + PASS (*out++ = y [4]); + PASS (*out++ = y [5]); + + delete[] x; + delete[] y; +} + +/***********************************************************************/ + +static void +test_2 () +{ + UserClass *x = UserClass::from_char ("abcdef"); + UserClass *y = UserClass::from_char ("ABCDEF"); + + OutputIter out = make_iter (x + 0, x + 0, x + 6, out); + + PASS (*out = y [0]); + PASS (++out); + PASS (out = y [1]); + PASS (++out); + PASS (*out = y [2]); + PASS (++out); + PASS (out = y [3]); + PASS (++out); + PASS (*out = y [4]); + PASS (++out); + PASS (out = y [5]); + PASS (++out); + + delete[] x; + delete[] y; +} + +/***********************************************************************/ + +static void +test_3 () +{ + UserClass *x = UserClass::from_char ("abcdef"); + UserClass *y = UserClass::from_char ("ABCDEF"); + + OutputIter out = make_iter (x + 0, x + 0, x + 6, out); + + PASS (*out = y [0]); + PASS (out++); + PASS (out = y [1]); + PASS (out++); + PASS (*out = y [2]); + PASS (out++); + PASS (out = y [3]); + PASS (out++); + PASS (*out = y [4]); + PASS (out++); + PASS (out = y [5]); + PASS (out++); + + delete[] x; + delete[] y; +} + +/***********************************************************************/ + +static void +test_4 () +{ + UserClass *x = UserClass::from_char ("abcdef"); + UserClass *y = UserClass::from_char ("ABCDEF"); + + OutputIter out = make_iter (x + 0, x + 0, x + 6, out); + + PASS (*out++ = y [0]); + PASS (*out = y [1]); + PASS (out++); + + PASS (out++ = y [2]); + PASS (out = y [3]); + PASS (out++); + + PASS (*out++ = y [4]); + PASS (*out = y [5]); + PASS (out++); + + delete[] x; + delete[] y; +} + +/***********************************************************************/ + +static void +test_5 () +{ + UserClass *x = UserClass::from_char ("abcdef"); + UserClass *y = UserClass::from_char ("ABCDEF"); + + OutputIter out = make_iter (x + 0, x + 0, x + 6, out); + + PASS (*out = y [0]); + PASS (++out); + PASS (*out++ = y [1]); + + PASS (out = y [2]); + PASS (++out); + PASS (out++ = y [3]); + + PASS (*out = y [4]); + PASS (++out); + PASS (*out++ = y [5]); + + delete[] x; + delete[] y; +} + +/***********************************************************************/ + +static void +test_6 () +{ + UserClass *x = UserClass::from_char ("abcdef"); + UserClass *y = UserClass::from_char ("ABCDEF"); + + OutputIter out = make_iter (x + 0, x + 0, x + 6, out); + + PASS (*out = y [0]); + PASS (*++out = y [1]); + PASS (++out = y [2]); + PASS (*++out = y [3]); + PASS (++out = y [4]); + PASS (*++out = y [5]); + PASS (out++); + + delete[] x; + delete[] y; +} + +/***********************************************************************/ + +static void +test_7 () +{ + UserClass x; + + OutputIter out = make_iter (&x, &x, &x, out); + + FAIL (++out); + FAIL (out++); + FAIL (*out); + FAIL (*out++); + FAIL (*out = x); + FAIL (*out++ = x); + FAIL (*++out = x); + FAIL (out = x); + FAIL (out++ = x); + FAIL (++out = x); + + out = make_iter (&x, &x, &x + 1, out); +} + +/***********************************************************************/ + +static void +test_8 () +{ + UserClass *x = UserClass::from_char ("abcdef"); + UserClass *y = UserClass::from_char ("ABCDEF"); + + OutputIter out = make_iter (x + 0, x + 0, x + 6, out); + + PASS (*out++ = y [0]); + PASS (*out++ = y [1]); + PASS (*out++ = y [2]); + PASS (*out++ = y [3]); + PASS (*out++ = y [4]); + PASS (*out++ = y [5]); + FAIL (out++); + + delete[] x; + delete[] y; +} + +/***********************************************************************/ + +static void +test_9 () +{ + UserClass *x = UserClass::from_char ("abcdef"); + UserClass *y = UserClass::from_char ("ABCDEF"); + + OutputIter out = make_iter (x + 0, x + 0, x + 6, out); + + PASS (*out++ = y [0]); + PASS (out++); + FAIL (*out++ = y [1]); + + delete[] x; + delete[] y; +} + +/***********************************************************************/ + +static int +run_test (int, char*[]) +{ +#ifndef NDEBUG + + // silence stderr output from invocations of the RW_ASSERT() macro + // that are expected to fail by design (i.e., that's what this test + // exercises) + fclose (stderr); + + test_1 (); + test_2 (); + test_3 (); + test_4 (); + test_5 (); + test_6 (); + test_7 (); + test_8 (); + test_9 (); + +#else // if defined (NDEBUG) + + rw_assert (0, 0, __LINE__, "macro NDEBUG #defined, cannot test"); + +#endif // NDEBUG + + return exit_status; + +} + +/***********************************************************************/ + +int main (int argc, char *argv[]) +{ + return rw_test (argc, argv, __FILE__, + 0 /* no clause */, + 0 /* no comment */, run_test, + 0 /* co command line options */); +} Propchange: incubator/stdcxx/trunk/tests/self/0.outputiter.cpp ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/stdcxx/trunk/tests/self/0.outputiter.cpp ------------------------------------------------------------------------------ svn:keywords = Id