diff --git a/test/OrderedStatic/Makefile b/test/OrderedStatic/Makefile new file mode 100755 index 0000000..c02cbbf --- /dev/null +++ b/test/OrderedStatic/Makefile @@ -0,0 +1,32 @@ + + +CPP = g++ +CC = gcc +OBJ = main.o +LINKOBJ = main.o +CXXINCS = -I./../../include -I. +LIBS = -L../../lib -lloki +CXXFLAGS = $(CXXINCS) -O2 -DNDEBUG -pedantic +BIN = main-gcc.exe +RM = rm -f +CHK_DIR_EXISTS= if not exist +MKDIR = mkdir + +.PHONY: all all-before all-after clean clean-custom + +all: all-before $(BIN) all-after + + +clean: clean-custom + ${RM} $(OBJ) $(BIN) + +$(BIN): $(OBJ) + $(CPP) $(LINKOBJ) -o main-gcc.exe $(LIBS) + +check_tmp: + @$(CHK_DIR_EXISTS) "" $(MKDIR) "tmp" + +main.o: main.cpp + $(CPP) -c main.cpp -o main.o $(CXXFLAGS) + + diff --git a/test/OrderedStatic/main.cpp b/test/OrderedStatic/main.cpp new file mode 100755 index 0000000..e0f63a4 --- /dev/null +++ b/test/OrderedStatic/main.cpp @@ -0,0 +1,106 @@ +//////////////////////////////////////////////////////////////////////////////// +// The Loki Library +// Copyright (c) 2005 Peter Kümmel +// Permission to use, copy, modify, distribute and sell this software for any +// purpose is hereby granted without fee, provided that the above copyright +// notice appear in all copies and that both that copyright notice and this +// permission notice appear in supporting documentation. +// The author makes no representations about the +// suitability of this software for any purpose. It is provided "as is" +// without express or implied warranty. +//////////////////////////////////////////////////////////////////////////////// + +// $Header: + +// define to test the OrderedStatic template +#define TEST_ORDERED_STATIC + +// define to see a runtime crash when not using OrderedStatic +//#define LOKI_CLASS_LEVEL_THREADING + +#include "loki/Functor.h" +#include + +#ifdef TEST_ORDERED_STATIC +#include "loki/OrderedStatic.h" +#endif + +struct L1 +{ + L1(){std::cout << "create L1: " << this << "\n";} + ~L1(){std::cout << "delete L1: " << this <<" \n";} +}; + +struct L2 +{ + L2(){std::cout << "create L2 \n";} + ~L2(){std::cout << "delete L2 \n";} +}; + +int f() +{ + std::cout << "f called \n"; + return 0; +} + +std::string func(); + + +#ifdef TEST_ORDERED_STATIC + +Loki::OrderedStatic<1,L1> l1; +Loki::OrderedStatic<2,L2> l2; + +Loki::OrderedStatic<1, std::string, std::string(*)() > s1( &func ); +Loki::OrderedStatic<2, std::string, LOKI_TYPELIST_1(char *) > s2( "s2" ); + +Loki::OrderedStatic<1, Loki::Functor, LOKI_TYPELIST_1( int(*)() ) > f1(f); + +#else + +L1 l1; +L2 l2; + +std::string s1( func() ); +std::string s2("s2"); + +Loki::Functor f1(f); + +#endif + + +std::string func() +{ +#ifdef TEST_ORDERED_STATIC + return *s2; +#else + return s2; +#endif +} + + +int main() +{ + +#ifdef TEST_ORDERED_STATIC + + Loki::OrderedStaticManager::Instance().createObjects(); + + (*f1)(); + + std::cout << "s1 = " << (*s1).c_str() << "\n"; + std::cout << "s2 = " << (*s2).c_str() << "\n"; + + +#else + + f1(); + + std::cout << "s1 = " << s1.c_str() << "\n"; + std::cout << "s2 = " << s2.c_str() << "\n"; + +#endif + + return 0; +} + diff --git a/test/OrderedStatic/make.msvc.bat b/test/OrderedStatic/make.msvc.bat new file mode 100755 index 0000000..2a29747 --- /dev/null +++ b/test/OrderedStatic/make.msvc.bat @@ -0,0 +1,13 @@ +if not exist tmp\ mkdir tmp + +cl -c -Zm200 -O2 -DNDEBUG -MT -EHsc -GR -W4 -wd4710 -I"." -I"..\..\include" -Fotmp\ main.cpp + +if not defined LOKI_MSVC_NOLIB ( + +link /NOLOGO /SUBSYSTEM:CONSOLE /incremental:no /OUT:"main-msvc.exe" ..\..\lib\loki.lib tmp\main.obj + +) else ( + +link /NOLOGO /SUBSYSTEM:CONSOLE /incremental:no /OUT:"main-msvc.exe" tmp\main.obj tmp\OrderedStatic.obj ..\..\lib\SmallObj.obj ..\..\lib\Singleton.obj + +)