Quellcode durchsuchen

Move lolunit.h to lol-core because it makes sense.

legacy
Sam Hocevar vor 5 Jahren
Ursprung
Commit
d1a24228a2
38 geänderte Dateien mit 60 neuen und 554 gelöschten Zeilen
  1. +0
    -1
      build/msbuild/lol.rules.props
  2. +0
    -1
      configure.ac
  3. +1
    -1
      lol-core
  4. +0
    -5
      src/t/Makefile.am
  5. +2
    -3
      src/t/base/array.cpp
  6. +2
    -3
      src/t/base/avl_tree.cpp
  7. +2
    -3
      src/t/base/enum.cpp
  8. +2
    -3
      src/t/base/map.cpp
  9. +2
    -3
      src/t/base/string.cpp
  10. +2
    -3
      src/t/base/types.cpp
  11. +2
    -3
      src/t/entity/camera.cpp
  12. +1
    -2
      src/t/image/color.cpp
  13. +2
    -3
      src/t/image/image.cpp
  14. +2
    -3
      src/t/math/array2d.cpp
  15. +2
    -3
      src/t/math/array3d.cpp
  16. +2
    -3
      src/t/math/arraynd.cpp
  17. +2
    -3
      src/t/math/bigint.cpp
  18. +2
    -3
      src/t/math/box.cpp
  19. +2
    -3
      src/t/math/cmplx.cpp
  20. +2
    -3
      src/t/math/half.cpp
  21. +2
    -3
      src/t/math/interp.cpp
  22. +2
    -3
      src/t/math/matrix.cpp
  23. +2
    -3
      src/t/math/noise/simplex.cpp
  24. +2
    -3
      src/t/math/numbers.cpp
  25. +1
    -2
      src/t/math/polynomial.cpp
  26. +2
    -3
      src/t/math/quat.cpp
  27. +2
    -3
      src/t/math/rand.cpp
  28. +1
    -2
      src/t/math/real.cpp
  29. +2
    -3
      src/t/math/rotation.cpp
  30. +2
    -3
      src/t/math/sqt.cpp
  31. +2
    -3
      src/t/math/trig.cpp
  32. +2
    -3
      src/t/math/vector.cpp
  33. +2
    -3
      src/t/sys/thread.cpp
  34. +2
    -4
      src/t/sys/timer.cpp
  35. +2
    -3
      src/t/test-common.cpp
  36. +0
    -1
      tools/Makefile.am
  37. +0
    -5
      tools/lolunit/Makefile.am
  38. +0
    -449
      tools/lolunit/lolunit.h

+ 0
- 1
build/msbuild/lol.rules.props Datei anzeigen

@@ -29,7 +29,6 @@
$(LolDir)\lol-core\include;
$(LolDir)\src;
$(LolDir)\src\3rdparty\bullet3\src;
$(LolDir)\tools\lolunit;
$(PegtlIncludes);
$(ImguiIncludes);
$(BtPhysIncludes);


+ 0
- 1
configure.ac Datei anzeigen

@@ -271,7 +271,6 @@ AC_CONFIG_FILES(
doc/samples/sandbox/Makefile
doc/tutorial/Makefile
tools/Makefile
tools/lolunit/Makefile
tools/vimlol/Makefile
tools/vslol/Makefile
])


+ 1
- 1
lol-core

@@ -1 +1 @@
Subproject commit 02bb54bdf96af1ddacfa35b397c1caf7bf30e4e4
Subproject commit c6960306484a771d580572b810247265e8d25088

+ 0
- 5
src/t/Makefile.am Datei anzeigen

@@ -29,7 +29,6 @@ endif
test_base_SOURCES = test-common.cpp \
base/avl_tree.cpp base/array.cpp base/enum.cpp base/map.cpp \
base/string.cpp base/types.cpp
test_base_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/tools/lolunit
test_base_DEPENDENCIES = @LOL_DEPS@

test_math_SOURCES = test-common.cpp \
@@ -38,22 +37,18 @@ test_math_SOURCES = test-common.cpp \
math/quat.cpp math/rand.cpp math/real.cpp math/rotation.cpp \
math/trig.cpp math/vector.cpp math/polynomial.cpp math/noise/simplex.cpp \
math/bigint.cpp math/sqt.cpp math/numbers.cpp
test_math_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/tools/lolunit
test_math_DEPENDENCIES = @LOL_DEPS@

test_sys_SOURCES = test-common.cpp \
sys/thread.cpp sys/timer.cpp
test_sys_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/tools/lolunit
test_sys_DEPENDENCIES = @LOL_DEPS@

test_image_SOURCES = test-common.cpp \
image/color.cpp image/image.cpp
test_image_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/tools/lolunit
test_image_DEPENDENCIES = @LOL_DEPS@

test_entity_SOURCES = test-common.cpp \
entity/camera.cpp
test_entity_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/tools/lolunit
test_entity_DEPENDENCIES = @LOL_DEPS@

EXTRA_DIST += data/gradient.png


+ 2
- 3
src/t/base/array.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,8 +11,7 @@
//

#include <lol/engine-internal.h>

#include <lolunit.h>
#include <lol/base/lolunit.h>

namespace lol
{


+ 2
- 3
src/t/base/avl_tree.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
// © 2013—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
// © 2013—2015 Guillaume Bittoun <guillaume.bittoun@gmail.com>
//
@@ -13,8 +13,7 @@
//

#include <lol/engine-internal.h>

#include <lolunit.h>
#include <lol/base/lolunit.h>

namespace lol
{


+ 2
- 3
src/t/base/enum.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,8 +11,7 @@
//

#include <lol/engine-internal.h>

#include <lolunit.h>
#include <lol/base/lolunit.h>

#include <string>
#include <map>


+ 2
- 3
src/t/base/map.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,11 +11,10 @@
//

#include <lol/engine-internal.h>
#include <lol/base/lolunit.h>

#include <map>

#include <lolunit.h>

namespace lol
{



+ 2
- 3
src/t/base/string.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
// © 2014—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
//
// Lol Engine is free software. It comes without any warranty, to
@@ -12,11 +12,10 @@
//

#include <lol/engine-internal.h>
#include <lol/base/lolunit.h>

#include <string>

#include <lolunit.h>

namespace lol
{



+ 2
- 3
src/t/base/types.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,8 +11,7 @@
//

#include <lol/engine-internal.h>

#include <lolunit.h>
#include <lol/base/lolunit.h>

namespace lol
{


+ 2
- 3
src/t/entity/camera.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests for the camera object
//
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
// © 2013 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
//
// Lol Engine is free software. It comes without any warranty, to
@@ -12,8 +12,7 @@
//

#include <lol/engine-internal.h>

#include <lolunit.h>
#include <lol/base/lolunit.h>

#include <memory>



+ 1
- 2
src/t/image/color.cpp Datei anzeigen

@@ -11,8 +11,7 @@
//

#include <lol/engine-internal.h>

#include <lolunit.h>
#include <lol/base/lolunit.h>

namespace lol
{


+ 2
- 3
src/t/image/image.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2017 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,11 +11,10 @@
//

#include <lol/engine-internal.h>
#include <lol/base/lolunit.h>

#include <cmath>

#include <lolunit.h>

namespace lol
{



+ 2
- 3
src/t/math/array2d.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,8 +11,7 @@
//

#include <lol/engine-internal.h>

#include <lolunit.h>
#include <lol/base/lolunit.h>

namespace lol
{


+ 2
- 3
src/t/math/array3d.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,8 +11,7 @@
//

#include <lol/engine-internal.h>

#include <lolunit.h>
#include <lol/base/lolunit.h>

namespace lol
{


+ 2
- 3
src/t/math/arraynd.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,8 +11,7 @@
//

#include <lol/engine-internal.h>

#include <lolunit.h>
#include <lol/base/lolunit.h>

namespace lol
{


+ 2
- 3
src/t/math/bigint.cpp Datei anzeigen

@@ -11,12 +11,11 @@
//

#include <lol/engine-internal.h>
#include <lol/base/lolunit.h>
#include <lol/types/bigint.h>

#include <cmath>

#include <lol/types/bigint.h>
#include <lolunit.h>

namespace lol
{



+ 2
- 3
src/t/math/box.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,8 +11,7 @@
//

#include <lol/engine-internal.h>

#include <lolunit.h>
#include <lol/base/lolunit.h>

namespace lol
{


+ 2
- 3
src/t/math/cmplx.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,8 +11,7 @@
//

#include <lol/engine-internal.h>

#include <lolunit.h>
#include <lol/base/lolunit.h>

namespace lol
{


+ 2
- 3
src/t/math/half.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,11 +11,10 @@
//

#include <lol/engine-internal.h>
#include <lol/base/lolunit.h>

#include <cmath>

#include <lolunit.h>

namespace lol
{



+ 2
- 3
src/t/math/interp.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,8 +11,7 @@
//

#include <lol/engine-internal.h>

#include <lolunit.h>
#include <lol/base/lolunit.h>

namespace lol
{


+ 2
- 3
src/t/math/matrix.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,8 +11,7 @@
//

#include <lol/engine-internal.h>

#include <lolunit.h>
#include <lol/base/lolunit.h>

namespace lol
{


+ 2
- 3
src/t/math/noise/simplex.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
// © 2013—2014 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
// © 2013—2014 Guillaume Bittoun <guillaume.bittoun@gmail.com>
//
@@ -13,8 +13,7 @@
//

#include <lol/engine-internal.h>

#include <lolunit.h>
#include <lol/base/lolunit.h>

namespace lol
{


+ 2
- 3
src/t/math/numbers.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests for number theory
//
// Copyright © 2010—2018 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,8 +11,7 @@
//

#include <lol/engine-internal.h>

#include <lolunit.h>
#include <lol/base/lolunit.h>

namespace lol
{


+ 1
- 2
src/t/math/polynomial.cpp Datei anzeigen

@@ -11,10 +11,9 @@
//

#include <lol/engine-internal.h>
#include <lol/base/lolunit.h>
#include <lol/types/real.h>
#include <lol/math/polynomial.h>
#include <lolunit.h>

namespace lol
{


+ 2
- 3
src/t/math/quat.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests for quaternions
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,8 +11,7 @@
//

#include <lol/engine-internal.h>

#include <lolunit.h>
#include <lol/base/lolunit.h>

namespace lol
{


+ 2
- 3
src/t/math/rand.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,8 +11,7 @@
//

#include <lol/engine-internal.h>

#include <lolunit.h>
#include <lol/base/lolunit.h>

namespace lol
{


+ 1
- 2
src/t/math/real.cpp Datei anzeigen

@@ -11,9 +11,8 @@
//

#include <lol/engine-internal.h>
#include <lol/base/lolunit.h>
#include <lol/types/real.h>
#include <lolunit.h>

#include <cmath>



+ 2
- 3
src/t/math/rotation.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests for rotations (matrices and quaternions)
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,8 +11,7 @@
//

#include <lol/engine-internal.h>

#include <lolunit.h>
#include <lol/base/lolunit.h>

namespace lol
{


+ 2
- 3
src/t/math/sqt.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests for the SQT transform class
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,8 +11,7 @@
//

#include <lol/engine-internal.h>

#include <lolunit.h>
#include <lol/base/lolunit.h>

namespace lol
{


+ 2
- 3
src/t/math/trig.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests for trigonometric functions
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,11 +11,10 @@
//

#include <lol/engine-internal.h>
#include <lol/base/lolunit.h>

#include <cmath>

#include <lolunit.h>

namespace lol
{



+ 2
- 3
src/t/math/vector.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,8 +11,7 @@
//

#include <lol/engine-internal.h>

#include <lolunit.h>
#include <lol/base/lolunit.h>

namespace lol
{


+ 2
- 3
src/t/sys/thread.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2019 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
// © 2014—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
//
// Lol Engine is free software. It comes without any warranty, to
@@ -12,12 +12,11 @@
//

#include <lol/engine-internal.h>
#include <lol/base/lolunit.h>

#include <string>
#include <map>

#include <lolunit.h>

namespace lol
{



+ 2
- 4
src/t/sys/timer.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
// © 2014—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
// © 2014—2015 Guillaume Bittoun <guillaume.bittoun@gmail.com>
//
@@ -13,10 +13,8 @@
//

#include <lol/engine-internal.h>
#include <lol/base/lolunit.h>

#include <lolunit.h>

#include <iostream>
namespace lol
{



+ 2
- 3
src/t/test-common.cpp Datei anzeigen

@@ -1,7 +1,7 @@
//
// Lol Engine — Unit tests
//
// Copyright © 2010—2015 Sam Hocevar <sam@hocevar.net>
// Copyright © 2010—2020 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
@@ -11,12 +11,11 @@
//

#include <lol/engine-internal.h>
#include <lol/base/lolunit.h>

#include <cstdio>
#include <cstdlib>

#include <lolunit.h>

int main(int argc, char **argv)
{
UNUSED(argc, argv);


+ 0
- 1
tools/Makefile.am Datei anzeigen

@@ -2,7 +2,6 @@
include $(top_srcdir)/build/autotools/common.am

SUBDIRS =
SUBDIRS += lolunit
SUBDIRS += vimlol
SUBDIRS += vslol



+ 0
- 5
tools/lolunit/Makefile.am Datei anzeigen

@@ -1,5 +0,0 @@

include $(top_srcdir)/build/autotools/common.am

EXTRA_DIST += lolunit.h


+ 0
- 449
tools/lolunit/lolunit.h Datei anzeigen

@@ -1,449 +0,0 @@
//
// Lol Engine — Unit test implementation
//
// Copyright © 2010—2016 Sam Hocevar <sam@hocevar.net>
//
// Lol Engine is free software. It comes without any warranty, to
// the extent permitted by applicable law. You can redistribute it
// and/or modify it under the terms of the Do What the Fuck You Want
// to Public License, Version 2, as published by the WTFPL Task Force.
// See http://www.wtfpl.net/ for more details.
//

#pragma once

//
// The Unit test framework
// -----------------------
//

#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#if defined _XBOX
# include <xtl.h>
# undef near /* Fuck Microsoft */
# undef far /* Fuck Microsoft again */
#elif defined _WIN32
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
# undef near /* Fuck Microsoft */
# undef far /* Fuck Microsoft again */
#endif

namespace lol
{

/*
* This is the base class for all fixtures. It keeps track of all
* fixtures registered through the lolunit_declare_fixture macro and puts them
* in a linked list.
*/
class FixtureBase
{
friend class text_runner;

public:
virtual void setup(void) {};
virtual void teardown(void) {};

protected:
FixtureBase() : m_next(NULL), m_testcases(0), m_failcases(0) {}
virtual ~FixtureBase() {}

static void AddFixture(FixtureBase *fixture)
{
/* Protect against several instances of the same Fixture subclass */
if (fixture->MarkFixture())
return;
FixtureListHelper(fixture);
}
static FixtureBase *FixtureList() { return FixtureListHelper(NULL); }

virtual void RunFixture() = 0;
virtual bool MarkFixture() = 0;

/* Prevent compiler complaints about unreachable code */
static inline bool True() { return true; }

FixtureBase *m_next;
int m_testcases, m_failcases;
int m_asserts, m_failure;
char const *m_fixturename, *m_currentname;
std::stringstream m_errorlog, m_context;

private:
/* The FixtureBase class keeps track of all instanciated children
* fixtures through this method. */
static FixtureBase *FixtureListHelper(FixtureBase *set)
{
static FixtureBase *head = NULL, *tail = NULL;

if (set)
{
if (!head) head = set;
if (tail) tail->m_next = set;
tail = set;
}
return head;
}
};

/*
* This template specialises FixtureBase and provides registration of
* test cases in a linked list through the lolunit_declare_test macro.
*/
template<class T> class Fixture : protected FixtureBase
{
public:
typedef T FixtureClass;

struct TestCase
{
void (FixtureClass::* m_fun)();
char const *m_testname;
TestCase *m_next;

protected:
static inline std::string make_msg(std::string const str)
{
return "- " + str + "\n";
}
};

Fixture()
{
AddFixture(this);
}

/* Run all test cases in this fixture. */
virtual void RunFixture()
{
m_errorlog.str("");
m_testcases = 0;
m_failcases = 0;
for (TestCase *c = TestCaseList(); c; c = c->m_next)
{
m_testcases++;
m_asserts = 0;
m_failure = false;
m_currentname = c->m_testname;
m_context.str("");

std::cout << '.';
(static_cast<FixtureClass *>(this)->*c->m_fun)();
if (m_failure) std::cout << 'F';
}
}

/* Mark the current fixture type as already registered and return whether
* it was seen before. */
virtual bool MarkFixture()
{
static bool seen = false;
if (seen)
{
SealFixture();
return true;
}
seen = true;
return false;
}

/* Manage Fixture sealing. Once SealFixture() has been called, we
* will no longer accept TestCase registrations. */
static void SealFixture() { SealFixtureHelper(true); }
static bool IsFixtureSealed() { return SealFixtureHelper(false); }

/* Each Fixture class specialisation keeps track of its instanciated
* test cases. */
static void AddTestCase(TestCase *that, char const *name,
void (FixtureClass::*fun)())
{
if (IsFixtureSealed())
return;

that->m_fun = fun;
that->m_testname = name;
that->m_next = NULL;
TestCaseListHelper(that);
}
static TestCase *TestCaseList() { return TestCaseListHelper(NULL); }

private:
static bool SealFixtureHelper(bool set)
{
static bool sealed = false;
if (set) sealed = true;
return sealed;
}

static TestCase *TestCaseListHelper(TestCase *set)
{
static TestCase *head = NULL, *tail = NULL;
if (set)
{
if (!head) head = set;
if (tail) tail->m_next = set;
tail = set;
}
return head;
}
};

/*
* This simple class runs all automatically registered tests and reports
* on error and success in the standard output.
*/
class text_runner
{
public:
bool Run()
{
bool ret = true;
std::stringstream errors("");
int failcases = 0, testcases = 0;

for (FixtureBase *f = FixtureBase::FixtureList(); f; f = f->m_next)
{
f->setup();
f->RunFixture();
f->teardown();

errors << f->m_errorlog.str();
testcases += f->m_testcases;
failcases += f->m_failcases;
}
std::cout << "\n";

std::stringstream summary;
summary << "\n\n";
if (failcases)
{
summary << "!!!FAILURES!!!\n";
summary << "Test Results:\n";
summary << "Run: " << testcases
<< " Failures: " << failcases
<< " Errors: 0\n"; /* TODO: handle errors */
summary << errors.str();

ret = false;
}
else
{
summary << "OK (" << testcases << " tests)\n";
}
summary << "\n\n";

#if _WIN32
::OutputDebugStringA(summary.str().c_str());
#else
std::cout << summary.str();
#endif

return ret;
}
};

#define lolunit_assert_generic(msg, cond) \
do { \
m_asserts++; \
if (True() && !(cond)) \
{ \
m_errorlog << "\n\n"; \
m_errorlog << ++m_failcases << ") test: " \
<< lol_unit_helper_name(this) << "::" << m_currentname \
<< " (F) line: " << __LINE__ << " " \
<< __FILE__ << "\n"; \
m_errorlog << "assertion failed\n"; \
m_errorlog << "- Expression: " << #cond << "\n"; \
m_errorlog << msg; \
m_failure = true; \
return; \
} \
} while (!True())

#define lolunit_assert_op(op, modifier, opdesc, msg, a, b) \
do { \
m_asserts++; \
if (True() && !modifier((a) op (b))) \
{ \
m_errorlog << "\n\n"; \
m_errorlog << ++m_failcases << ") test: " \
<< lol_unit_helper_name(this) << "::" << m_currentname \
<< " (F) line: " << __LINE__ << " " \
<< __FILE__ << "\n"; \
m_errorlog << opdesc << " assertion failed\n"; \
m_errorlog << "- Expected: " << #a << " = " << (a) << "\n"; \
m_errorlog << "- Actual : " << #b << " = " << (b) << "\n"; \
m_errorlog << msg; \
m_errorlog << m_context.str(); \
m_failure = true; \
return; \
} \
} while (!True())

#define lolunit_assert_doubles_equal_generic(msg, a, b, t) \
do { \
m_asserts++; \
using std::fabs; \
if (True() && fabs(double(a) - double(b)) > fabs(double(t))) \
{ \
m_errorlog << "\n\n"; \
m_errorlog << ++m_failcases << ") test: " \
<< lol_unit_helper_name(this) << "::" << m_currentname \
<< " (F) line: " << __LINE__ << " " \
<< __FILE__ << "\n"; \
m_errorlog << "double equality assertion failed\n"; \
std::streamsize old_prec = m_errorlog.precision(); \
m_errorlog << std::setprecision(16); \
m_errorlog << "- Expected: " << #a << " = " << (a) << "\n"; \
m_errorlog << "- Actual : " << #b << " = " << (b) << "\n"; \
m_errorlog << "- Delta : " << (t) << "\n"; \
m_errorlog << std::setprecision(old_prec); \
m_errorlog << msg; \
m_errorlog << m_context.str(); \
m_failure = true; \
return; \
} \
} while (!True())

/*
* Public helper macros
*/

#define lolunit_declare_fixture(N) \
class N; \
/* This pattern allows us to statically create a Fixture instance \
* before its exact implementation was defined. */ \
template<typename T> struct lol_unit_helper_fixture_##N \
{ \
lol_unit_helper_fixture_##N() { p = new T(); } \
~lol_unit_helper_fixture_##N() { delete p; } \
T *p; \
}; \
lol_unit_helper_fixture_##N<N> lol_unit_helper_fixture_##N##_instance; \
/* Allow to retrieve the class name without using RTTI and without \
* knowing the type of "this". */ \
static inline char const *lol_unit_helper_name(N *p) \
{ \
(void)p; \
return #N; \
} \
/* Now the user can define the implementation */ \
class N : public lol::Fixture<N>

#define lolunit_declare_test(N) \
/* For each test in the fixture, we create an object that will \
* automatically register the test method in a list global to the \
* specialised fixture. */ \
class lol_unit_helper_test_##N : public TestCase \
{ \
public: \
lol_unit_helper_test_##N() \
{ \
(void)lol_unit_helper_name(nullptr); \
AddTestCase(this, #N, \
(void (FixtureClass::*)()) &FixtureClass::N); \
} \
}; \
lol_unit_helper_test_##N lol_unit_helper_test_instance_##N; \
void N()

/*
* Provide context for error messages
*/

#define lolunit_set_context(n) \
do { \
m_context.str(""); \
m_context << "- Context : " << #n << " = " << (n) << "\n"; \
} while (!True())

#define lolunit_unset_context(n) \
m_context.str("")

/*
* Public assert macros
*/

#define lolunit_fail(msg) \
do { \
m_asserts++; \
m_errorlog << "\n\n"; \
m_errorlog << ++m_failcases << ") test: " \
<< lol_unit_helper_name(this) << "::" << m_currentname \
<< " (F) line: " << __LINE__ << " " \
<< __FILE__ << "\n"; \
m_errorlog << "forced failure\n"; \
m_errorlog << make_msg(msg); \
m_errorlog << m_context.str(); \
m_failure = true; \
return; \
} while (!True())

#define lolunit_assert(cond) \
lolunit_assert_generic("", cond)
#define lolunit_assert_message(m, cond) \
lolunit_assert_generic(make_msg(m), cond)


#define lolunit_assert_equal(a, b) \
lolunit_assert_op(==, (bool), "equality", "", a, b)
#define lolunit_assert_equal_message(m, a, b) \
lolunit_assert_op(==, (bool), "equality", make_msg(m), a, b)
#define lolunit_assert_different(a, b) \
lolunit_assert_op(!=, (bool), "inequality", "", a, b)
#define lolunit_assert_different_message(m, a, b) \
lolunit_assert_op(!=, (bool), "inequality", make_msg(m), a, b)
#define lolunit_assert_less(a, b) \
lolunit_assert_op(<, (bool), "less than", "", a, b)
#define lolunit_assert_less_message(m, a, b) \
lolunit_assert_op(<, (bool), "less than", make_msg(m), a, b)
#define lolunit_assert_lequal(a, b) \
lolunit_assert_op(<=, (bool), "less than or equal", "", a, b)
#define lolunit_assert_lequal_message(m, a, b) \
lolunit_assert_op(<=, (bool), "less than or equal", make_msg(m), a, b)
#define lolunit_assert_greater(a, b) \
lolunit_assert_op(>, (bool), "greater than", "", a, b)
#define lolunit_assert_greater_message(m, a, b) \
lolunit_assert_op(>, (bool), "greater than", make_msg(m), a, b)
#define lolunit_assert_gequal(a, b) \
lolunit_assert_op(>=, (bool), "greater than or equal", "", a, b)
#define lolunit_assert_gequal_message(m, a, b) \
lolunit_assert_op(>=, (bool), "greater than or equal", make_msg(m), a, b)


#define lolunit_refute_equal(a, b) \
lolunit_assert_op(==, !, "not equality", "", a, b)
#define lolunit_refute_equal_message(m, a, b) \
lolunit_assert_op(==, !, "not equality", make_msg(m), a, b)
#define lolunit_refute_different(a, b) \
lolunit_assert_op(!=, !, "not inequality", "", a, b)
#define lolunit_refute_different_message(m, a, b) \
lolunit_assert_op(!=, !, "not inequality", make_msg(m), a, b)
#define lolunit_refute_less(a, b) \
lolunit_assert_op(<, !, "not less than", "", a, b)
#define lolunit_refute_less_message(m, a, b) \
lolunit_assert_op(<, !, "not less than", make_msg(m), a, b)
#define lolunit_refute_lequal(a, b) \
lolunit_assert_op(<=, !, "not less than or equal", "", a, b)
#define lolunit_refute_lequal_message(m, a, b) \
lolunit_assert_op(<=, !, "not less than or equal", make_msg(m), a, b)
#define lolunit_refute_greater(a, b) \
lolunit_assert_op(>, !, "not greater than", "", a, b)
#define lolunit_refute_greater_message(m, a, b) \
lolunit_assert_op(>, !, "not greater than", make_msg(m), a, b)
#define lolunit_refute_gequal(a, b) \
lolunit_assert_op(>=, !, "not greater than or equal", "", a, b)
#define lolunit_refute_gequal_message(m, a, b) \
lolunit_assert_op(>=, !, "not greater than or equal", make_msg(m), a, b)

#define lolunit_assert_doubles_equal(a, b, t) \
lolunit_assert_doubles_equal_generic("", a, b, t)
#define lolunit_assert_doubles_equal_message(msg, a, b, t) \
lolunit_assert_doubles_equal_generic(make_msg(msg), a, b, t)

} /* namespace lol */


Laden…
Abbrechen
Speichern