genericopenlibs/cppstdlib/stl/test/unit/generator_test.cpp
changeset 31 ce057bb09d0b
child 34 5fae379060a7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/genericopenlibs/cppstdlib/stl/test/unit/generator_test.cpp	Fri Jun 04 16:20:51 2010 +0100
@@ -0,0 +1,108 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: 
+*
+*/
+#include <vector>
+#include <algorithm>
+#include "fadapter.h"
+#include "fib.h"
+
+#include "cppunit/cppunit_proxy.h"
+
+#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
+using namespace std;
+#endif
+
+//
+// TestCase class
+//
+class GeneratorTest : public CPPUNIT_NS::TestCase
+{
+  CPPUNIT_TEST_SUITE(GeneratorTest);
+  CPPUNIT_TEST(gener1);
+  CPPUNIT_TEST(gener2);
+  CPPUNIT_TEST(genern1);
+  CPPUNIT_TEST(genern2);
+  CPPUNIT_TEST_SUITE_END();
+
+protected:
+  void gener1();
+  void gener2();
+  void genern1();
+  void genern2();
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(GeneratorTest);
+
+//
+// tests implementation
+//
+
+static  int cxxrand() { return rand();}
+
+void GeneratorTest::gener1()
+{
+  int numbers[10];
+#if defined(__MVS__)
+  generate(numbers, numbers + 10, ptr_gen(cxxrand));
+#else
+  generate(numbers, numbers + 10, cxxrand);
+#endif
+  // any suggestions?
+}
+void GeneratorTest::gener2()
+{
+  vector <int> v1(10);
+  Fibonacci generator;
+  generate(v1.begin(), v1.end(), generator);
+
+  CPPUNIT_ASSERT(v1[0]==1);
+  CPPUNIT_ASSERT(v1[1]==1);
+  CPPUNIT_ASSERT(v1[2]==2);
+  CPPUNIT_ASSERT(v1[3]==3);
+  CPPUNIT_ASSERT(v1[4]==5);
+  CPPUNIT_ASSERT(v1[5]==8);
+  CPPUNIT_ASSERT(v1[6]==13);
+  CPPUNIT_ASSERT(v1[7]==21);
+  CPPUNIT_ASSERT(v1[8]==34);
+  CPPUNIT_ASSERT(v1[9]==55);
+}
+void GeneratorTest::genern1()
+{
+#if !defined (_STLP_MEMBER_POINTER_PARAM_BUG)
+  //*TY 07/18/98 - added conditional
+  // since ptr_gen() is not defined under this condition
+  // (see xfunction.h)
+  vector <int> v1(10);
+  generate_n(v1.begin(), v1.size(), ptr_gen(cxxrand));
+#endif  //_STLP_MEMBER_POINTER_PARAM_BUG  //*TY 07/18/98 - added
+}
+void GeneratorTest::genern2()
+{
+  vector <int> v1(10);
+  Fibonacci generator;
+  generate_n(v1.begin(), v1.size(), generator);
+
+  CPPUNIT_ASSERT(v1[0]==1);
+  CPPUNIT_ASSERT(v1[1]==1);
+  CPPUNIT_ASSERT(v1[2]==2);
+  CPPUNIT_ASSERT(v1[3]==3);
+  CPPUNIT_ASSERT(v1[4]==5);
+  CPPUNIT_ASSERT(v1[5]==8);
+  CPPUNIT_ASSERT(v1[6]==13);
+  CPPUNIT_ASSERT(v1[7]==21);
+  CPPUNIT_ASSERT(v1[8]==34);
+  CPPUNIT_ASSERT(v1[9]==55);
+}