This commit is contained in:
jeanlemotan
2024-07-02 18:10:39 +02:00
commit 48ab06b1d9
733 changed files with 321088 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
tags
cscope.out
**/*.swp
**/*.swo
.swp
*.swp
.swo
.TMP
-.d
eastl_build_out
build_bench
bench.bat
build.bat
.p4config
## CMake generated files
CMakeCache.txt
cmake_install.cmake
## Patch files
*.patch
## For Visual Studio Generated projects
*.sln
**/*.vcxproj
**/*.vcxproj.filters
*.VC.opendb
*.sdf
**/*.suo
**/*.user
.vs/*
**/Debug/*
CMakeFiles/*
EASTL.dir/**
RelWithDebInfo/*
Release/*
Win32/*
x64/*
MinSizeRel/*
build*/*
Testing/*
%ALLUSERSPROFILE%/*
# Buck
/buck-out/
/.buckd/
/buckaroo/
.buckconfig.local
BUCKAROO_DEPS
+18
View File
@@ -0,0 +1,18 @@
[submodule "test/packages/EAMain"]
path = test/packages/EAMain
url = git@github.com:electronicarts/EAMain.git
[submodule "test/packages/EAStdC"]
path = test/packages/EAStdC
url = git@github.com:electronicarts/EAStdC.git
[submodule "test/packages/EAAssert"]
path = test/packages/EAAssert
url = git@github.com:electronicarts/EAAssert.git
[submodule "test/packages/EAThread"]
path = test/packages/EAThread
url = git@github.com:electronicarts/EAThread.git
[submodule "test/packages/EASTL"]
path = test/packages/EASTL
url = git@github.com:electronicarts/EASTL.git
[submodule "test/packages/EABase"]
path = test/packages/EABase
url = git@github.com:electronicarts/EABase.git
+68
View File
@@ -0,0 +1,68 @@
language: cpp
os:
- linux
- osx
- windows
compiler:
- gcc
- clang
- msvc
env:
- EA_CONFIG=Debug
- EA_CONFIG=Release
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- george-edison55-precise-backports
- llvm-toolchain-trusty-7
packages:
- cmake
- cmake-data
- g++-7
- clang-7
matrix:
exclude:
- os: osx
compiler: gcc
- os: osx
compiler: msvc
- os: linux
compiler: msvc
- os: windows
compiler: clang
- os: windows
compiler: gcc
# Handle git submodules yourself
git:
submodules: false
# Use sed to replace the SSH URL with the public URL, then initialize submodules
before_install:
- sed --version >/dev/null 2>&1 && sed -i 's/git@github.com:/https:\/\/github.com\//' .gitmodules || sed -i "" 's/git@github.com:/https:\/\/github.com\//' .gitmodules
- git submodule update --init
install:
- if [[ "$CXX" == "g++" ]]; then export CC="gcc-7" ;fi
- if [[ "$CXX" == "g++" ]]; then export CXX="g++-7" ;fi
- if [[ "$CXX" == "clang++" && "${TRAVIS_OS_NAME}" != "osx" ]]; then export CC="clang-7" ;fi
- if [[ "$CXX" == "clang++" && "${TRAVIS_OS_NAME}" != "osx" ]]; then export CXX="clang++-7" ;fi
# Universal Setup
before_script:
- mkdir build_$EA_CONFIG
- cd build_$EA_CONFIG
- cmake .. -DEATEST_BUILD_TESTS:BOOL=ON
- cmake --build . --config $EA_CONFIG
script:
# Run Tests
- cd $TRAVIS_BUILD_DIR/build_$EA_CONFIG/test
- ctest -C $EA_CONFIG -V || exit 1
+47
View File
@@ -0,0 +1,47 @@
#-------------------------------------------------------------------------------------------
# Copyright (C) Electronic Arts Inc. All rights reserved.
#-------------------------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.1)
project(EATest CXX)
#-------------------------------------------------------------------------------------------
# Options
#-------------------------------------------------------------------------------------------
option(EATEST_BUILD_TESTS "Enable generation of build files for tests" OFF)
#-------------------------------------------------------------------------------------------
# Compiler Flags
#-------------------------------------------------------------------------------------------
set (CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/test/packages/EASTL/scripts/CMake")
include(CommonCppFlags)
#-------------------------------------------------------------------------------------------
# Library definition
#-------------------------------------------------------------------------------------------
file(GLOB EATEST_SOURCES "source/*.cpp")
add_library(EATest ${EATEST_SOURCES})
if(EATEST_BUILD_TESTS)
add_subdirectory(test)
endif()
#-------------------------------------------------------------------------------------------
# Defines
#-------------------------------------------------------------------------------------------
add_definitions(-D_CHAR16T)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
#-------------------------------------------------------------------------------------------
# Include directories
#-------------------------------------------------------------------------------------------
target_include_directories(EATest PUBLIC include)
#-------------------------------------------------------------------------------------------
# Dependencies
#-------------------------------------------------------------------------------------------
target_link_libraries(EATest EABase)
target_link_libraries(EATest EAStdC)
target_link_libraries(EATest EASTL)
target_link_libraries(EATest EAMain)
target_link_libraries(EATest EAThread)
+73
View File
@@ -0,0 +1,73 @@
## Contributing
Before you can contribute, EA must have a Contributor License Agreement (CLA) on file that has been signed by each contributor.
You can sign here: [Go to CLA](https://electronicarts.na1.echosign.com/public/esignWidget?wid=CBFCIBAA3AAABLblqZhByHRvZqmltGtliuExmuV-WNzlaJGPhbSRg2ufuPsM3P0QmILZjLpkGslg24-UJtek*)
### Pull Request Policy
All code contributions are submitted as [Github pull requests](https://help.github.com/articles/using-pull-requests/). All pull requests will be reviewed by a maintainer according to the guidelines found in the next section.
Your pull request should:
* merge cleanly
* come with tests
* tests should be minimal and stable
* fail before your fix is applied
* pass the test suite
* code formatting is encoded in clang format
* limit using clang format on new code
* do not deviate from style already established in the files
### Running the Unit Tests
EAAssert uses CMake as its build system.
* Create and navigate to "your_build_folder":
* mkdir your_build_folder && cd your_build_folder
* Generate build scripts:
* cmake source_folder -DEATEST_BUILD_TESTS:BOOL=ON
* Build unit tests for "your_config":
* cmake --build . --config your_config
* Run the unit tests for "your_config" from the test folder:
* cd test && ctest -C your_config
Here is an example batch file.
```batch
set build_folder=out
mkdir %build_folder%
pushd %build_folder%
call cmake .. -DEATEST_BUILD_TESTS:BOOL=ON
call cmake --build . --config Release
call cmake --build . --config Debug
call cmake --build . --config RelWithDebInfo
call cmake --build . --config MinSizeRel
pushd test
call ctest -C Release
call ctest -C Debug
call ctest -C RelWithDebInfo
call ctest -C MinSizeRel
popd
popd
```
Here is an example bash file
```bash
build_folder=out
mkdir $build_folder
pushd $build_folder
cmake .. -DEATEST_BUILD_TESTS:BOOL=ON
cmake --build . --config Release
cmake --build . --config Debug
cmake --build . --config RelWithDebInfo
cmake --build . --config MinSizeRel
pushd test
ctest -C Release
ctest -C Debug
ctest -C RelWithDebInfo
ctest -C MinSizeRel
popd
popd
```
+27
View File
@@ -0,0 +1,27 @@
/*
Copyright (C) 2017 Electronic Arts Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of Electronic Arts, Inc. ("EA") nor the names of
its contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY ELECTRONIC ARTS AND ITS CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL ELECTRONIC ARTS OR ITS CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+21
View File
@@ -0,0 +1,21 @@
# EATest
[![Build Status](https://travis-ci.org/electronicarts/EATest.svg?branch=master)](https://travis-ci.org/electronicarts/EATest)
EATest is a C++ unit testing framework. It's goal is to have a scalable architecture, have minimal dependencies, and simple usage.
## Compiling sources
Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details on compiling and testing the source.
## Credits
Roberto Parolin is the current EATest owner within EA and is responsible for the open source repository.
## License
Modified BSD License (3-Clause BSD license) see the file LICENSE in the project root.
@@ -0,0 +1,34 @@
///////////////////////////////////////////////////////////////////////////////
// EAMissingImpl.inl
//
// Copyright (c) Electronic Arts Inc. All rights reserved.
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// *** Note ***
//
// You must compile this file into your main executable and not into a .lib
// file, otherwise it will not work with GCC and may not work with VC++.
// The C++ standard supports overriding operator new, in which case it will
// override that provided by the library vendor. However, in practice you need
// to compile your operator new into your main executable and not in a library
// that you make. This is so because the linker doesn't know how to distinguish
// between your .lib file and the C runtime .lib files.
///////////////////////////////////////////////////////////////////////////////
#ifndef EAMISSINGIMPL_INL
#define EAMISSINGIMPL_INL
#include <time.h>
#endif // Header include guard
@@ -0,0 +1,33 @@
///////////////////////////////////////////////////////////////////////////////
// EASTLNewOperatorGuard.inl
//
// Copyright (c) Electronic Arts. All Rights Reserved.
///////////////////////////////////////////////////////////////////////////////
#include <EABase/eabase.h>
#include <EAAssert/eaassert.h>
#ifndef EATEST_EASTLNEWOPERATORGUARD_INL
#define EATEST_EASTLNEWOPERATORGUARD_INL
///////////////////////////////////////////////////////////////////////////////
// EASTL requires the following new operators to be defined.
// They are provided here due to linkage requirements only.
///////////////////////////////////////////////////////////////////////////////
EA_DISABLE_CLANG_WARNING(-Wnew-returns-null)
void* operator new[](size_t, const char*, int, unsigned, const char*, int)
{
EA_FAIL_MSG("Unexpected call to global new operator. Does EASTL have an ICoreAllocator set?");
return nullptr;
}
void* operator new[](size_t, size_t, size_t, const char*, int, unsigned, const char*, int)
{
EA_FAIL_MSG("Unexpected call to global new operator. Does EASTL have an ICoreAllocator set?");
return nullptr;
}
EA_RESTORE_CLANG_WARNING()
#endif // header include guard
@@ -0,0 +1,41 @@
///////////////////////////////////////////////////////////////////////////////
// EASTLVsnprintf.inl
//
// Copyright (c) Electronic Arts. All Rights Reserved.
///////////////////////////////////////////////////////////////////////////////
#ifndef EATEST_EASTLVSNPRINTF_INL
#define EATEST_EASTLVSNPRINTF_INL
#include <EAStdC/EASprintf.h>
// Until EASTL is switched to using EAStdC vsnprintf natively, we need to provide the following.
int Vsnprintf8(char* pDestination, size_t n, const char* pFormat, va_list arguments)
{
return EA::StdC::Vsnprintf(pDestination, n, pFormat, arguments);
}
int Vsnprintf16(char16_t* pDestination, size_t n, const char16_t* pFormat, va_list arguments)
{
return EA::StdC::Vsnprintf(pDestination, n, pFormat, arguments);
}
int Vsnprintf32(char32_t* pDestination, size_t n, const char32_t* pFormat, va_list arguments)
{
return EA::StdC::Vsnprintf(pDestination, n, pFormat, arguments);
}
#if defined(EA_WCHAR_UNIQUE) && EA_WCHAR_UNIQUE
int VsnprintfW(wchar_t* pDestination, size_t n, const wchar_t* pFormat, va_list arguments)
{
return EA::StdC::Vsnprintf(pDestination, n, pFormat, arguments);
}
#endif
#endif // EATEST_EASTLVSNPRINTF_INL
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,154 @@
///////////////////////////////////////////////////////////////////////////////
// Config.h
//
// Copyright (c) Electronic Arts Inc. All rights reserved.
///////////////////////////////////////////////////////////////////////////////
#ifndef EATEST_INTERNAL_CONFIG_H
#define EATEST_INTERNAL_CONFIG_H
#include <EABase/eabase.h>
//#include <EABase/eahave.h> Disabled until eahave.h stabilizes.
///////////////////////////////////////////////////////////////////////////////
// EATEST_VERSION
//
// We more or less follow the conventional EA packaging approach to versioning
// here. A primary distinction here is that minor versions are defined as two
// digit entities (e.g. .03") instead of minimal digit entities ".3"). The logic
// here is that the value is a counter and not a floating point fraction.
// Note that the major version doesn't have leading zeros.
//
// Example version strings:
// "0.91.00" // Major version 0, minor version 91, patch version 0.
// "1.00.00" // Major version 1, minor and patch version 0.
// "3.10.02" // Major version 3, minor version 10, patch version 02.
// "12.03.01" // Major version 12, minor version 03, patch version
//
// Example usage:
// printf("EATEST version: %s", EATEST_VERSION);
// printf("EATEST version: %d.%d.%d", EATEST_VERSION_N / 10000 % 100, EATEST_VERSION_N / 100 % 100, EATEST_VERSION_N % 100);
//
///////////////////////////////////////////////////////////////////////////////
#ifndef EATEST_VERSION
#define EATEST_VERSION "2.08.08"
#define EATEST_VERSION_N 20808
#endif
///////////////////////////////////////////////////////////////////////////////
// EA_HAVE_SYS_PTRACE_H
//
// Defined or not defined, as per <EABase/eahave.h>
//
#if !defined(EA_HAVE_SYS_PTRACE_H) && !defined(EA_NO_HAVE_SYS_PTRACE_H)
#if defined(EA_PLATFORM_UNIX) && !defined(__CYGWIN__) && (defined(EA_PLATFORM_DESKTOP) || defined(EA_PLATFORM_SERVER))
#define EA_HAVE_SYS_PTRACE_H 1 /* declares the ptrace function */
#else
#define EA_NO_HAVE_SYS_PTRACE_H 1
#endif
#endif
///////////////////////////////////////////////////////////////////////////////
// EATEST_ALIGNMENT_EXCEPTION_DETECTION_CALLED
//
// Defined as 0 or 1.
// Specifies whether EnableAlignmentExceptionDetection is automatically called
// upon running tests.
//
#if !defined(EATEST_ALIGNMENT_EXCEPTION_DETECTION_CALLED)
#define EATEST_ALIGNMENT_EXCEPTION_DETECTION_CALLED 1
#endif
///////////////////////////////////////////////////////////////////////////////
// EATEST_ALLOC_PREFIX
//
// Defined as a string literal. Defaults to this package's name.
// Can be overridden by the user by predefining it or by editing this file.
// This define is used as the default name used by this package for naming
// memory allocations and memory allocators.
//
// All allocations names follow the same naming pattern:
// <package>/<module>[/<specific usage>]
//
// Example usage:
// void* p = pCoreAllocator->Alloc(37, EATEST_ALLOC_PREFIX, 0);
//
// Example usage:
// gMessageServer.GetMessageQueue().get_allocator().set_name(EATEST_ALLOC_PREFIX "MessageSystem/Queue");
//
#ifndef EATEST_ALLOC_PREFIX
#define EATEST_ALLOC_PREFIX "EATEST/"
#endif
///////////////////////////////////////////////////////////////////////////////
// EATEST_DLL
//
// Defined as 0 or 1. The default is dependent on the definition of EA_DLL.
// If EA_DLL is defined, then EATEST_DLL is 1, else EATEST_DLL is 0.
// EA_DLL is a define that controls DLL builds within the EAConfig build system.
// EATEST_DLL controls whether EATEST is built and used as a DLL.
// Normally you wouldn't do such a thing, but there are use cases for such
// a thing, particularly in the case of embedding C++ into C# applications.
//
#ifndef EATEST_DLL
#if defined(EA_DLL)
#define EATEST_DLL 1
#else
#define EATEST_DLL 0
#endif
#endif
///////////////////////////////////////////////////////////////////////////////
// EATEST_API
//
// This is used to label functions as DLL exports under Microsoft platforms.
// If EA_DLL is defined, then the user is building EATest as a DLL and EATest's
// non-templated functions will be exported. EATest template functions are not
// labelled as EATEST_API (and are thus not exported in a DLL build). This is
// because it's not possible (or at least unsafe) to implement inline templated
// functions in a DLL.
//
// Example usage of EATEST_API:
// EATEST_API int someVariable = 10; // Export someVariable in a DLL build.
//
// struct EATEST_API SomeClass{ // Export SomeClass and its member functions in a DLL build.
// EATEST_LOCAL void PrivateMethod(); // Not exported.
// };
//
// EATEST_API void SomeFunction(); // Export SomeFunction in a DLL build.
//
// For GCC, see http://gcc.gnu.org/wiki/Visibility
//
#ifndef EATEST_API // If the build file hasn't already defined this to be dllexport...
#if EATEST_DLL
#if defined(_MSC_VER)
#define EATEST_API __declspec(dllimport)
#define EATEST_LOCAL
#elif defined(__CYGWIN__)
#define EATEST_API __attribute__((dllimport))
#define EATEST_LOCAL
#elif (defined(__GNUC__) && (__GNUC__ >= 4))
#define EATEST_API __attribute__ ((visibility("default")))
#define EATEST_LOCAL __attribute__ ((visibility("hidden")))
#else
#define EATEST_API
#define EATEST_LOCAL
#endif
#else
#define EATEST_API
#define EATEST_LOCAL
#endif
#endif
#endif // Header include guard
File diff suppressed because it is too large Load Diff
+74
View File
@@ -0,0 +1,74 @@
#-------------------------------------------------------------------------------------------
# Copyright (C) Electronic Arts Inc. All rights reserved.
#-------------------------------------------------------------------------------------------
#-------------------------------------------------------------------------------------------
# CMake info
#-------------------------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.1)
project(EATestTest CXX)
include(CTest)
#-------------------------------------------------------------------------------------------
# Defines
#-------------------------------------------------------------------------------------------
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
add_definitions(-D_CHAR16T)
#-------------------------------------------------------------------------------------------
# Compiler Flags
#-------------------------------------------------------------------------------------------
set (CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/packages/EASTL/scripts/CMake")
include(CommonCppFlags)
#-------------------------------------------------------------------------------------------
# Source files
#-------------------------------------------------------------------------------------------
file(GLOB EATESTTEST_SOURCES "source/*.cpp")
set(SOURCES ${EATESTTEST_SOURCES})
#-------------------------------------------------------------------------------------------
# Executable definition
#-------------------------------------------------------------------------------------------
add_executable(EATestTest ${SOURCES})
#-------------------------------------------------------------------------------------------
# Include directories
#-------------------------------------------------------------------------------------------
target_include_directories(EATestTest PUBLIC include)
#-------------------------------------------------------------------------------------------
# Dependencies
#-------------------------------------------------------------------------------------------
add_subdirectory(packages/EAAssert)
add_subdirectory(packages/EABase)
add_subdirectory(packages/EAMain)
add_subdirectory(packages/EASTL)
add_subdirectory(packages/EAStdC)
add_subdirectory(packages/EAThread)
target_link_libraries(EATestTest EAAssert)
target_link_libraries(EATestTest EABase)
target_link_libraries(EATestTest EAMain)
target_link_libraries(EATestTest EASTL)
target_link_libraries(EATestTest EAStdC)
target_link_libraries(EATestTest EATest)
target_link_libraries(EATestTest EAThread)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
if((NOT APPLE) AND (NOT WIN32))
target_link_libraries(EATestTest ${EASTLTest_Libraries} Threads::Threads rt)
else()
target_link_libraries(EATestTest ${EASTLTest_Libraries} Threads::Threads)
endif()
#-------------------------------------------------------------------------------------------
# Run Unit tests and verify the results.
#-------------------------------------------------------------------------------------------
add_test(EATestTestRuns EATestTest)
set_tests_properties (EATestTestRuns PROPERTIES PASS_REGULAR_EXPRESSION "RETURNCODE=0")
+385
View File
@@ -0,0 +1,385 @@
///////////////////////////////////////////////////////////////////////////////
// main.cpp
//
// Copyright (c) Electronic Arts Inc. All rights reserved.
///////////////////////////////////////////////////////////////////////////////
#include <EABase/eabase.h>
#include <EATest/EATest.h>
#include <EAMain/EAEntryPointMain.inl>
#include <EAStdC/EAString.h>
#ifdef _MSC_VER
#pragma warning(push, 0)
#endif
#include <stdio.h>
#include <stdlib.h>
#if defined(EA_COMPILER_MSVC) && defined(EA_PLATFORM_MICROSOFT)
#include <crtdbg.h>
#endif
#ifdef _MSC_VER
#pragma warning(pop)
#endif
void* operator new[](size_t size, const char* /*pName*/, int /*flags*/, unsigned /*debugFlags*/, const char* /*file*/, int /*line*/)
{
return operator new(size);
}
void* operator new[](size_t size, size_t /*alignment*/, size_t /*alignmentOffset*/, const char* /*pName*/,
int /*flags*/, unsigned /*debugFlags*/, const char* /*file*/, int /*line*/)
{
return operator new(size);
}
void operator delete[] (void* ptr) EA_THROW_SPEC_DELETE_NONE()
{
operator delete(ptr);
}
// Test1
// Does nothing except return a value.
class Test1 : public EA::UnitTest::Test
{
public:
Test1(const char8_t* pTestName, bool bShouldSucceed = true)
: Test(pTestName), mnRunCount(10), mbShouldSucceed(bShouldSucceed) {}
int Run()
{
using namespace EA::UnitTest;
EA_DISABLE_VC_WARNING(6326)
Verify(1 < 2, "Failure of (1 < 2) comparison.");
EA_RESTORE_VC_WARNING()
if(--mnRunCount > 0)
return kTestResultContinue;
WriteReport();
return mbShouldSucceed ? kTestResultOK : kTestResultError;
}
int mnRunCount;
bool mbShouldSucceed;
};
// Test2
// Does nothing except return a value.
class Test2 : public EA::UnitTest::Test
{
public:
Test2(const char8_t* pTestName, bool bShouldSucceed = true)
: Test(pTestName), mnRunCount(10), mbShouldSucceed(bShouldSucceed) {}
int Run()
{
using namespace EA::UnitTest;
EA_DISABLE_VC_WARNING(6326)
Verify(1 < 2, "Failure of (1 < 2) comparison.");
EA_RESTORE_VC_WARNING()
if(--mnRunCount > 0)
return kTestResultContinue;
WriteReport();
return mbShouldSucceed ? kTestResultOK : kTestResultError;
}
int mnRunCount;
bool mbShouldSucceed;
};
// TestFunction1
// Does nothing except return a value.
static int TestFunction1()
{
using namespace EA::UnitTest;
static int nRunCount(10);
if(--nRunCount > 0)
return kTestResultContinue;
nRunCount = 10;
return kTestResultOK;
}
// TestFunction1
// Does nothing except return a value.
static int TestFunction2()
{
return 0;
}
static int TestFunction3()
{
return 0;
}
static int TestFunction4()
{
return 0;
}
// TestClass1
// Does nothing except return a value.
struct TestClass1
{
int DoTest();
};
int TestClass1::DoTest()
{
return 0;
}
///////////////////////////////////////////////////////////////////////////////
// EAMain
//
static int TestMisc()
{
int nErrorCount(0);
using namespace EA::UnitTest;
{ // Test standalone functions.
// In many of these cases we don't validate the results but rather simply make sure they return rational values and don't crash.
bool result = EA::UnitTest::IsDebuggerPresent();
Report("Debugger is %s.\n", result ? "present" : "absent");
result = IsUserAdmin();
Report("User is currently %s.\n", result ? "admin" : "not admin");
unsigned verbosity = GetVerbosity();
Report("Test verbosity is %d.\n", verbosity);
ThreadSleep(100);
ThreadSleepRandom(10, 20, false);
ThreadSleepRandom(10, 20, true);
uint64_t time64 = GetSystemTimeMicroseconds();
Report("System time us = %I64u.\n", time64);
if (!IsRunningUnderValgrind())
{
SetHighThreadPriority();
SetNormalThreadPriority();
//SetLowProcessPriority(); // Currently disabled because we don't currently have a way to set it back to normal priority.
}
if(GetInteractive())
MessageBoxAlert("Message box test", "Message Box Test");
NonInlinableFunction();
int& value = WriteToEnsureFunctionCalled();
EA_UNUSED(value);
float systemSpeed = GetSystemSpeed(kSpeedTypeCPU);
Report("System kSpeedTypeCPU %.1f.\n", systemSpeed);
systemSpeed = GetSystemSpeed(kSpeedTypeFPU);
Report("System kSpeedTypeFPU %.1f.\n", systemSpeed);
systemSpeed = GetSystemSpeed(kSpeedTypeGPU);
Report("System kSpeedTypeGPU %.1f.\n", systemSpeed);
systemSpeed = GetSystemSpeed(kSpeedTypeDisk);
Report("System kSpeedTypeDisk %.1f.\n", systemSpeed);
uint64_t memory64 = GetSystemMemoryMB();
Report("System memory %I64u.\n", memory64);
uint32_t seed = GetRandSeed();
Report("Test random seed %I32u.\n", seed);
}
{ // Test the Report functions.
Report(NULL, "Test of %s.\n", "Report()");
Report("Test of %s.\n", "Report()");
Report("Report()\n");
}
{ // Test the VERIFY macro.
EATEST_VERIFY(__LINE__ != 0);
EATEST_VERIFY(1 != 2);
EATEST_VERIFY(((uintptr_t)&nErrorCount % 2) == 0);
EATEST_VERIFY_MSG(__LINE__ != 0, "EATEST_VERIFY_MSG");
EATEST_VERIFY_MSG(1 != 2, "EATEST_VERIFY_MSG");
EATEST_VERIFY_MSG(((uintptr_t)&nErrorCount % 2) == 0, "EATEST_VERIFY_MSG");
#if !defined(EA_COMPILER_NO_VARIADIC_MACROS)
EATEST_VERIFY_F(__LINE__ != 0, "%s", "EATEST_VERIFY_F");
EATEST_VERIFY_F(1 != 2, "%s", "EATEST_VERIFY_F");
EATEST_VERIFY_F(((uintptr_t)&nErrorCount % 2) == 0, "%s", "EATEST_VERIFY_F");
#endif
}
{ // Test class Test
// Test for OK return.
Test1 test1OK("Test1", true);
int nResult;
while((nResult = test1OK.Run()) == kTestResultContinue)
; // Do nothing.
EATEST_VERIFY_MSG(nResult == kTestResultOK, "Failure in test1OK.");
// Test for Error return.
Test1 test1Error("Test1", false);
while((nResult = test1Error.Run()) == kTestResultContinue)
; // Do nothing.
EATEST_VERIFY_MSG(nResult == kTestResultError, "Failure in test1Error.");
}
{ // Test class TestFunction
TestFunction testFunction("TestFunction1", TestFunction1);
int nResult;
while((nResult = testFunction.Run()) == kTestResultContinue)
; // Do nothing.
EATEST_VERIFY_MSG(nResult == kTestResultOK, "Failure in TestFunction.");
}
{ // Test class TestMemberFunction
TestClass1 testClass1;
TestMemberFunction<TestClass1> class1Test("Test of TestClass1", &testClass1, &TestClass1::DoTest);
const int nResult = class1Test.Run();
EATEST_VERIFY_MSG(nResult == kTestResultOK, "Failure in TestClass1.");
}
{ // Test class TestSuite
TestSuite testSuite("Test suite");
int nResult;
// Test objects
Test1 test1("Test1");
testSuite.AddTest(&test1, false);
testSuite.AddTest(new Test2("Test2"), true);
// Test functions
testSuite.AddTest("TestFunction1", TestFunction1);
// Test member functions
TestClass1 testClass1;
testSuite.AddTest("Test of TestClass1", &testClass1, &TestClass1::DoTest);
// Test enumeration
size_t n1 = testSuite.EnumerateTests(0, 100);
EATEST_VERIFY_MSG(n1 == 4, "Failure in TestSuite.");
n1 = testSuite.EnumerateTests(NULL, 0); // Verify that NULL is treated as expected.
EATEST_VERIFY_MSG(n1 == 4, "Failure in TestSuite.");
n1 = testSuite.EnumerateTests(NULL, 100); // Verify that NULL is treated as expected.
EATEST_VERIFY_MSG(n1 == 4, "Failure in TestSuite.");
// Run tests
while((nResult = testSuite.Run()) == kTestResultContinue)
; // Do nothing.
EATEST_VERIFY_MSG(nResult == kTestResultOK, "Failure in TestSuite.");
}
{ // Test Rand
Rand rng(100);
for(int i = 0; i < 1000; i++)
{
/*int32_t y =*/ rng.RandValue();
// Hard to verify without full-blown randomness testing.
uint32_t z = rng.RandLimit(1000);
EATEST_VERIFY(z < 1000);
int32_t w = rng.RandRange(-50, +30);
EATEST_VERIFY((w >= -50) && (w < 30));
/*uint32_t x =*/ rng();
// Hard to verify without full-blown randomness testing.
uint32_t q = rng(100);
EATEST_VERIFY(q < 100);
}
uint32_t* pFirst = NULL, *pLast = NULL;
eastl::random_shuffle(pFirst, pLast, rng);
}
return nErrorCount;
}
///////////////////////////////////////////////////////////////////////////////
// EAMain
//
int EAMain(int argc, char** argv)
{
using namespace EA::UnitTest;
int nErrorCount(0);
{ // Test of the TestApplication class and the CommandLine class.
TestApplication testSuite("Test Unit Tests", argc, argv);
// Add all tests
testSuite.AddTest("Misc", TestMisc);
testSuite.AddTest("Function1", TestFunction1);
testSuite.AddTest("Function2", TestFunction2);
testSuite.AddTest("Function3", TestFunction3);
testSuite.AddTest("Function4", TestFunction4);
// Startup info
Report("**************************************************************************\n");
Report("* EATest test *\n");
Report("* *\n");
Report("* Available arguments: *\n");
Report("* -list Displays a list of available tests. *\n");
Report("* -run:<TestName> Runs a specified test or all if no name is present. *\n");
Report("* -wait[:yes | no] Waits at the end for a user confirmation. *\n");
Report("* *\n");
Report("* Example usage: *\n");
Report("* EATestTest.exe -list -wait *\n");
Report("* EATestTest.exe -run:DateTime -run:Random *\n");
Report("* EATestTest.exe -run:DateTime -wait:no *\n");
Report("* *\n");
Report("* Available tests: *\n");
testSuite.PrintTestNames(true);
Report("**************************************************************************\n\n");
const int testResult = testSuite.Run();
EATEST_VERIFY(testResult != 0x123456);
}
return nErrorCount;
}