add OrderedStatic test

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@284 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
syntheticpp 2005-10-05 17:57:54 +00:00
parent ab34afa8d6
commit b44c50216e
3 changed files with 151 additions and 0 deletions

32
test/OrderedStatic/Makefile Executable file
View file

@ -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)

106
test/OrderedStatic/main.cpp Executable file
View file

@ -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 <iostream>
#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<int>, LOKI_TYPELIST_1( int(*)() ) > f1(f);
#else
L1 l1;
L2 l2;
std::string s1( func() );
std::string s2("s2");
Loki::Functor<int> 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;
}

View file

@ -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
)