From 3a533730702bfe9adb418e23a59cec19590df12e Mon Sep 17 00:00:00 2001 From: Albin Johansson Date: Fri, 7 Jun 2024 21:42:54 +0200 Subject: [PATCH 01/34] Add SDL submodules --- .gitmodules | 12 ++++++++++++ external/SDL | 1 + external/SDL_image | 1 + external/SDL_mixer | 1 + external/SDL_ttf | 1 + 5 files changed, 16 insertions(+) create mode 160000 external/SDL create mode 160000 external/SDL_image create mode 160000 external/SDL_mixer create mode 160000 external/SDL_ttf diff --git a/.gitmodules b/.gitmodules index c1febb6fa..95ddc108b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,15 @@ [submodule "external/fff"] path = external/fff url = https://github.com/meekrosoft/fff +[submodule "external/SDL"] + path = external/SDL + url = https://github.com/libsdl-org/SDL +[submodule "external/SDL_image"] + path = external/SDL_image + url = https://github.com/libsdl-org/SDL_image +[submodule "external/SDL_ttf"] + path = external/SDL_ttf + url = https://github.com/libsdl-org/SDL_ttf +[submodule "external/SDL_mixer"] + path = external/SDL_mixer + url = https://github.com/libsdl-org/SDL_mixer diff --git a/external/SDL b/external/SDL new file mode 160000 index 000000000..a5356f9b4 --- /dev/null +++ b/external/SDL @@ -0,0 +1 @@ +Subproject commit a5356f9b45bc466824c964fde43471cbe74078e7 diff --git a/external/SDL_image b/external/SDL_image new file mode 160000 index 000000000..8eff782fa --- /dev/null +++ b/external/SDL_image @@ -0,0 +1 @@ +Subproject commit 8eff782fa33d795c9ea1ac42dbe7e17cc9874c78 diff --git a/external/SDL_mixer b/external/SDL_mixer new file mode 160000 index 000000000..3f45cc34e --- /dev/null +++ b/external/SDL_mixer @@ -0,0 +1 @@ +Subproject commit 3f45cc34ee327ee5d23d828c049d5a66316b6c73 diff --git a/external/SDL_ttf b/external/SDL_ttf new file mode 160000 index 000000000..df316fa22 --- /dev/null +++ b/external/SDL_ttf @@ -0,0 +1 @@ +Subproject commit df316fa22ea8ac84c53c8e78030b46ac81925df3 From 1766d7ae398add251ec5456f78c1167668ac819e Mon Sep 17 00:00:00 2001 From: Albin Johansson Date: Fri, 7 Jun 2024 21:44:37 +0200 Subject: [PATCH 02/34] Update .gitignore --- .gitignore | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 1af25237f..284b9775b 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ *.pch # Compiled Dynamic libraries +*.dll *.so *.dylib @@ -44,14 +45,21 @@ # Affinity Designer files *.afdesign -# JetBrains IDE files +# IDE files .idea - -# Visual Studio and VSCode files +.fleet .vs .vscode -bin/*.dll +# Build directories build cmake-build-* -doxygen-out + +# Python virtual environments +**/venv + +# Script files +scripts/.cache + +# Testing assets +assets From 0d263a5804baa0ea884075c82758c20dc81c06b9 Mon Sep 17 00:00:00 2001 From: Albin Johansson Date: Fri, 7 Jun 2024 21:45:19 +0200 Subject: [PATCH 03/34] Update .clang-format --- .clang-format | 183 +++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 166 insertions(+), 17 deletions(-) diff --git a/.clang-format b/.clang-format index cc5acd796..880e7a99c 100644 --- a/.clang-format +++ b/.clang-format @@ -1,42 +1,191 @@ BasedOnStyle: Google +# Language mode Language: Cpp Standard: c++20 -ColumnLimit: 95 +# Basic +UseTab: Never +ColumnLimit: 80 IndentWidth: 2 +ContinuationIndentWidth: 4 +MaxEmptyLinesToKeep: 1 +# Pointers and references DerivePointerAlignment: false PointerAlignment: Left +ReferenceAlignment: Left -IndentRequiresClause: true +# Qualifiers +QualifierAlignment: Custom +QualifierOrder: [ 'friend', 'inline', 'static', 'constexpr', 'const', 'volatile', 'restrict', 'type' ] +SpaceAroundPointerQualifiers: Default + +# Braces +InsertBraces: false +BracedInitializerIndentWidth: 2 +Cpp11BracedListStyle: true +SpaceBeforeCpp11BracedList: true +AllowShortBlocksOnASingleLine: Never +AlignArrayOfStructures: None +BreakBeforeBraces: Custom +BraceWrapping: + IndentBraces: false + AfterNamespace: false + AfterExternBlock: true + AfterClass: true + AfterStruct: true + AfterEnum: true + AfterUnion: true + AfterFunction: true + AfterCaseLabel: false + AfterControlStatement: Never + BeforeElse: true + BeforeCatch: true + BeforeWhile: false + BeforeLambdaBody: false + SplitEmptyNamespace: false + SplitEmptyFunction: false + SplitEmptyRecord: false + +# Spaces +SpaceBeforeParens: ControlStatementsExceptControlMacros +SpaceBeforeSquareBrackets: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpacesInParens: Never +SpacesInAngles: Never +SpacesInSquareBrackets: false +SpaceInEmptyBlock: false + +# Preprocessor +AlignConsecutiveMacros: None +AlignEscapedNewlines: Left +IndentPPDirectives: None +PPIndentWidth: 2 +SortIncludes: CaseSensitive +IncludeBlocks: Regroup +IncludeCategories: + # Standard headers, located in <> with no extension. + - Regex: '<[A-Za-z0-9\_\-]+>' + SortPriority: 1 + Priority: 1 + # Headers in <> with extension and optional prefix. + - Regex: '<.+>' + SortPriority: 2 + Priority: 2 + + # Headers in "" with extension. + - Regex: '".+"' + SortPriority: 3 + Priority: 3 + +# Operators +AlignOperands: Align +AlignConsecutiveDeclarations: None +AlignConsecutiveAssignments: None +SpaceBeforeAssignmentOperators: true +BreakBeforeTernaryOperators: true +BreakBeforeBinaryOperators: None + +# Control statements +AllowShortIfStatementsOnASingleLine: Never +AllowShortLoopsOnASingleLine: false + +# Attributes +BreakAfterAttributes: Leave + +# Namespaces NamespaceIndentation: None FixNamespaceComments: true +# Access modifiers +IndentAccessModifiers: false +AccessModifierOffset: -1 EmptyLineBeforeAccessModifier: Always +EmptyLineAfterAccessModifier: Never -AllowAllArgumentsOnNextLine: false -AllowAllParametersOfDeclarationOnNextLine: false -AllowAllConstructorInitializersOnNextLine: false +# Constructors +PackConstructorInitializers: Never +SpaceBeforeCtorInitializerColon: true +ConstructorInitializerIndentWidth: 2 +BreakConstructorInitializers: BeforeColon +# Inheritance +BreakInheritanceList: BeforeColon +SpaceBeforeInheritanceColon: true + +# Enums +AllowShortEnumsOnASingleLine: false + +# Functions +AlwaysBreakAfterReturnType: None +AllowShortFunctionsOnASingleLine: None +IndentWrappedFunctionNames: false +RemoveSemicolon: false BinPackParameters: false BinPackArguments: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowAllArgumentsOnNextLine: false +AllowBreakBeforeNoexceptSpecifier: OnlyWithParen -AllowShortFunctionsOnASingleLine: InlineOnly -AllowShortIfStatementsOnASingleLine: Never -AllowShortBlocksOnASingleLine: Empty +# Lambdas +LambdaBodyIndentation: Signature AllowShortLambdasOnASingleLine: All -AllowShortEnumsOnASingleLine: false -AllowShortLoopsOnASingleLine: false -BreakBeforeBinaryOperators: None -BreakBeforeTernaryOperators: true -BreakBeforeConceptDeclarations: true +# Templates +SpaceAfterTemplateKeyword: true +AlwaysBreakTemplateDeclarations: Yes + +# Concepts +IndentRequiresClause: true +BreakBeforeConceptDeclarations: Always +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +AllowShortCompoundRequirementOnASingleLine: true + +# Switches +AllowShortCaseLabelsOnASingleLine: true +SpaceBeforeCaseColon: false +IndentCaseLabels: true +IndentCaseBlocks: false +AlignConsecutiveShortCaseStatements: + Enabled: true + AcrossEmptyLines: false + AcrossComments: false + AlignCaseColons: false + +# Bit fields +AlignConsecutiveBitFields: Consecutive +BitFieldColonSpacing: Both + +# Digit separators +IntegerLiteralSeparator: + Binary: -1 + Decimal: 0 + Hex: -1 -BreakBeforeBraces: Stroustrup +# Strings +BreakStringLiterals: false +BreakAdjacentStringLiterals: false +AlwaysBreakBeforeMultilineStrings: false -BreakInheritanceList: BeforeComma -BreakConstructorInitializers: BeforeComma +# Comments +SpacesBeforeTrailingComments: 2 +ReflowComments: true +AlignTrailingComments: + Kind: Always + OverEmptyLines: 0 -SpaceBeforeCpp11BracedList: true \ No newline at end of file +# Miscellaneous +AlignAfterOpenBracket: Align +BreakArrays: false +SpacesInContainerLiterals: false +IndentGotoLabels: false +IndentExternBlock: Indent +KeepEmptyLinesAtTheStartOfBlocks: false +InsertNewlineAtEOF: true +SortUsingDeclarations: Lexicographic +RemoveParentheses: Leave From 7c31b3db2369f527430d2845012a282ba7cb430a Mon Sep 17 00:00:00 2001 From: Albin Johansson Date: Fri, 7 Jun 2024 21:45:25 +0200 Subject: [PATCH 04/34] Delete .gitkeep --- bin/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 bin/.gitkeep diff --git a/bin/.gitkeep b/bin/.gitkeep deleted file mode 100644 index e69de29bb..000000000 From 4a3cc9f831683ef16bd51a8a0526dc7ace6bb276 Mon Sep 17 00:00:00 2001 From: Albin Johansson Date: Fri, 7 Jun 2024 21:45:51 +0200 Subject: [PATCH 05/34] Remove SDL2 find scripts --- cmake/FindSDL2.cmake | 173 ------------------------------------- cmake/FindSDL2_image.cmake | 102 ---------------------- cmake/FindSDL2_mixer.cmake | 101 ---------------------- cmake/FindSDL2_ttf.cmake | 99 --------------------- 4 files changed, 475 deletions(-) delete mode 100644 cmake/FindSDL2.cmake delete mode 100644 cmake/FindSDL2_image.cmake delete mode 100644 cmake/FindSDL2_mixer.cmake delete mode 100644 cmake/FindSDL2_ttf.cmake diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake deleted file mode 100644 index 1cdfdaa80..000000000 --- a/cmake/FindSDL2.cmake +++ /dev/null @@ -1,173 +0,0 @@ - -# This module defines -# SDL2_LIBRARY, the name of the library to link against -# SDL2_FOUND, if false, do not try to link to SDL2 -# SDL2_INCLUDE_DIR, where to find SDL.h -# -# This module responds to the the flag: -# SDL2_BUILDING_LIBRARY -# If this is defined, then no SDL2main will be linked in because -# only applications need main(). -# Otherwise, it is assumed you are building an application and this -# module will attempt to locate and set the the proper link flags -# as part of the returned SDL2_LIBRARY variable. -# -# Don't forget to include SDLmain.h and SDLmain.m your project for the -# OS X framework based version. (Other versions link to -lSDL2main which -# this module will try to find on your behalf.) Also for OS X, this -# module will automatically add the -framework Cocoa on your behalf. -# -# -# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration -# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library -# (SDL2.dll, libsdl2.so, SDL2.framework, etc). -# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again. -# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value -# as appropriate. These values are used to generate the final SDL2_LIBRARY -# variable, but when these values are unset, SDL2_LIBRARY does not get created. -# -# -# $SDL2DIR is an environment variable that would -# correspond to the ./configure --prefix=$SDL2DIR -# used in building SDL2. -# l.e.galup 9-20-02 -# -# Modified by Eric Wing. -# Added code to assist with automated building by using environmental variables -# and providing a more controlled/consistent search behavior. -# Added new modifications to recognize OS X frameworks and -# additional Unix paths (FreeBSD, etc). -# Also corrected the header search path to follow "proper" SDL guidelines. -# Added a search for SDL2main which is needed by some platforms. -# Added a search for threads which is needed by some platforms. -# Added needed compile switches for MinGW. -# -# On OSX, this will prefer the Framework version (if found) over others. -# People will have to manually change the cache values of -# SDL2_LIBRARY to override this selection or set the CMake environment -# CMAKE_INCLUDE_PATH to modify the search paths. -# -# Note that the header path has changed from SDL2/SDL.h to just SDL.h -# This needed to change because "proper" SDL convention -# is #include "SDL.h", not . This is done for portability -# reasons because not all systems place things in SDL2/ (see FreeBSD). - -#============================================================================= -# Copyright 2003-2009 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -# message("") - -SET(SDL2_SEARCH_PATHS - ~/Library/Frameworks - /Library/Frameworks - /usr/local - /usr - /sw # Fink - /opt/local # DarwinPorts - /opt/csw # Blastwave - /opt - ${SDL2_PATH} - ) - -FIND_PATH(SDL2_INCLUDE_DIR SDL.h - HINTS - $ENV{SDL2DIR} - PATH_SUFFIXES include/SDL2 include - PATHS ${SDL2_SEARCH_PATHS} - ) - -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(PATH_SUFFIXES lib64 lib/x64 lib) -else() - set(PATH_SUFFIXES lib/x86 lib) -endif() - -FIND_LIBRARY(SDL2_LIBRARY_TEMP - NAMES SDL2 - HINTS - $ENV{SDL2DIR} - PATH_SUFFIXES ${PATH_SUFFIXES} - PATHS ${SDL2_SEARCH_PATHS} - ) - -IF(NOT SDL2_BUILDING_LIBRARY) - IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") - # Non-OS X framework versions expect you to also dynamically link to - # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms - # seem to provide SDL2main for compatibility even though they don't - # necessarily need it. - FIND_LIBRARY(SDL2MAIN_LIBRARY - NAMES SDL2main - HINTS - $ENV{SDL2DIR} - PATH_SUFFIXES ${PATH_SUFFIXES} - PATHS ${SDL2_SEARCH_PATHS} - ) - ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") -ENDIF(NOT SDL2_BUILDING_LIBRARY) - -# SDL2 may require threads on your system. -# The Apple build may not need an explicit flag because one of the -# frameworks may already provide it. -# But for non-OSX systems, I will use the CMake Threads package. -IF(NOT APPLE) - FIND_PACKAGE(Threads) -ENDIF(NOT APPLE) - -# MinGW needs an additional link flag, -mwindows -# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -mwindows -IF(MINGW) - SET(MINGW32_LIBRARY mingw32 "-mwindows" CACHE STRING "mwindows for MinGW") -ENDIF(MINGW) - -IF(SDL2_LIBRARY_TEMP) - # For SDL2main - IF(NOT SDL2_BUILDING_LIBRARY) - IF(SDL2MAIN_LIBRARY) - SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP}) - ENDIF(SDL2MAIN_LIBRARY) - ENDIF(NOT SDL2_BUILDING_LIBRARY) - - # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. - # CMake doesn't display the -framework Cocoa string in the UI even - # though it actually is there if I modify a pre-used variable. - # I think it has something to do with the CACHE STRING. - # So I use a temporary variable until the end so I can set the - # "real" variable in one-shot. - IF(APPLE) - SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa") - ENDIF(APPLE) - - # For threads, as mentioned Apple doesn't need this. - # In fact, there seems to be a problem if I used the Threads package - # and try using this line, so I'm just skipping it entirely for OS X. - IF(NOT APPLE) - SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT}) - ENDIF(NOT APPLE) - - # For MinGW library - IF(MINGW) - SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP}) - ENDIF(MINGW) - - # Set the final string here so the GUI reflects the final state. - SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found") - # Set the temp variable to INTERNAL so it is not seen in the CMake GUI - SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "") -ENDIF(SDL2_LIBRARY_TEMP) - -# message("") - -INCLUDE(FindPackageHandleStandardArgs) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR) diff --git a/cmake/FindSDL2_image.cmake b/cmake/FindSDL2_image.cmake deleted file mode 100644 index 591c1e6b0..000000000 --- a/cmake/FindSDL2_image.cmake +++ /dev/null @@ -1,102 +0,0 @@ -# Locate SDL_image library -# -# This module defines: -# -# :: -# -# SDL2_IMAGE_LIBRARIES, the name of the library to link against -# SDL2_IMAGE_INCLUDE_DIRS, where to find the headers -# SDL2_IMAGE_FOUND, if false, do not try to link against -# SDL2_IMAGE_VERSION_STRING - human-readable string containing the version of SDL_image -# -# -# -# For backward compatibility the following variables are also set: -# -# :: -# -# SDLIMAGE_LIBRARY (same value as SDL2_IMAGE_LIBRARIES) -# SDLIMAGE_INCLUDE_DIR (same value as SDL2_IMAGE_INCLUDE_DIRS) -# SDLIMAGE_FOUND (same value as SDL2_IMAGE_FOUND) -# -# -# -# $SDLDIR is an environment variable that would correspond to the -# ./configure --prefix=$SDLDIR used in building SDL. -# -# Created by Eric Wing. This was influenced by the FindSDL.cmake -# module, but with modifications to recognize OS X frameworks and -# additional Unix paths (FreeBSD, etc). - -#============================================================================= -# Copyright 2005-2009 Kitware, Inc. -# Copyright 2012 Benjamin Eikel -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -find_path(SDL2_IMAGE_INCLUDE_DIR SDL_image.h - HINTS - C:/ - ENV SDL2IMAGEDIR - ENV SDL2DIR - PATH_SUFFIXES SDL2 - # path suffixes to search inside ENV{SDLDIR} - include/SDL2 include - PATHS ${SDL2_IMAGE_PATH} - ) - -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(VC_LIB_PATH_SUFFIX lib/x64) -else() - set(VC_LIB_PATH_SUFFIX lib/x86) -endif() - -find_library(SDL2_IMAGE_LIBRARY - NAMES SDL2_image - HINTS - C:/SDL_image - ENV SDL2IMAGEDIR - ENV SDL2DIR - PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} - PATHS ${SDL2_IMAGE_PATH} - ) - -if(SDL2_IMAGE_INCLUDE_DIR AND EXISTS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h") - file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+[0-9]+$") - string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MAJOR "${SDL2_IMAGE_VERSION_MAJOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MINOR "${SDL2_IMAGE_VERSION_MINOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_PATCH "${SDL2_IMAGE_VERSION_PATCH_LINE}") - set(SDL2_IMAGE_VERSION_STRING ${SDL2_IMAGE_VERSION_MAJOR}.${SDL2_IMAGE_VERSION_MINOR}.${SDL2_IMAGE_VERSION_PATCH}) - unset(SDL2_IMAGE_VERSION_MAJOR_LINE) - unset(SDL2_IMAGE_VERSION_MINOR_LINE) - unset(SDL2_IMAGE_VERSION_PATCH_LINE) - unset(SDL2_IMAGE_VERSION_MAJOR) - unset(SDL2_IMAGE_VERSION_MINOR) - unset(SDL2_IMAGE_VERSION_PATCH) -endif() - -set(SDL2_IMAGE_LIBRARIES ${SDL2_IMAGE_LIBRARY}) -set(SDL2_IMAGE_INCLUDE_DIRS ${SDL2_IMAGE_INCLUDE_DIR}) - -include(FindPackageHandleStandardArgs) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_image - REQUIRED_VARS SDL2_IMAGE_LIBRARIES SDL2_IMAGE_INCLUDE_DIRS - VERSION_VAR SDL2_IMAGE_VERSION_STRING) - -# for backward compatibility -set(SDLIMAGE_LIBRARY ${SDL2_IMAGE_LIBRARIES}) -set(SDLIMAGE_INCLUDE_DIR ${SDL2_IMAGE_INCLUDE_DIRS}) -set(SDLIMAGE_FOUND ${SDL2_IMAGE_FOUND}) - -mark_as_advanced(SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR) diff --git a/cmake/FindSDL2_mixer.cmake b/cmake/FindSDL2_mixer.cmake deleted file mode 100644 index f3fc4f9b7..000000000 --- a/cmake/FindSDL2_mixer.cmake +++ /dev/null @@ -1,101 +0,0 @@ -# Locate SDL_MIXER library -# -# This module defines: -# -# :: -# -# SDL2_MIXER_LIBRARIES, the name of the library to link against -# SDL2_MIXER_INCLUDE_DIRS, where to find the headers -# SDL2_MIXER_FOUND, if false, do not try to link against -# SDL2_MIXER_VERSION_STRING - human-readable string containing the version of SDL_MIXER -# -# -# -# For backward compatibility the following variables are also set: -# -# :: -# -# SDLMIXER_LIBRARY (same value as SDL2_MIXER_LIBRARIES) -# SDLMIXER_INCLUDE_DIR (same value as SDL2_MIXER_INCLUDE_DIRS) -# SDLMIXER_FOUND (same value as SDL2_MIXER_FOUND) -# -# -# -# $SDLDIR is an environment variable that would correspond to the -# ./configure --prefix=$SDLDIR used in building SDL. -# -# Created by Eric Wing. This was influenced by the FindSDL.cmake -# module, but with modifications to recognize OS X frameworks and -# additional Unix paths (FreeBSD, etc). - -#============================================================================= -# Copyright 2005-2009 Kitware, Inc. -# Copyright 2012 Benjamin Eikel -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -find_path(SDL2_MIXER_INCLUDE_DIR SDL_mixer.h - HINTS - ENV SDL2MIXERDIR - ENV SDL2DIR - PATH_SUFFIXES SDL2 - # path suffixes to search inside ENV{SDLDIR} - include/SDL2 include - PATHS ${SDL2_MIXER_PATH} - ) - -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(VC_LIB_PATH_SUFFIX lib/x64) -else() - set(VC_LIB_PATH_SUFFIX lib/x86) -endif() - -find_library(SDL2_MIXER_LIBRARY - NAMES SDL2_mixer - HINTS - C:/SDL_mixer - ENV SDL2MIXERDIR - ENV SDL2DIR - PATH_SUFFIXES lib bin ${VC_LIB_PATH_SUFFIX} - PATHS ${SDL2_MIXER_PATH} - ) - -if(SDL2_MIXER_INCLUDE_DIR AND EXISTS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h") - file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+[0-9]+$") - string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MAJOR "${SDL2_MIXER_VERSION_MAJOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MINOR "${SDL2_MIXER_VERSION_MINOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_PATCH "${SDL2_MIXER_VERSION_PATCH_LINE}") - set(SDL2_MIXER_VERSION_STRING ${SDL2_MIXER_VERSION_MAJOR}.${SDL2_MIXER_VERSION_MINOR}.${SDL2_MIXER_VERSION_PATCH}) - unset(SDL2_MIXER_VERSION_MAJOR_LINE) - unset(SDL2_MIXER_VERSION_MINOR_LINE) - unset(SDL2_MIXER_VERSION_PATCH_LINE) - unset(SDL2_MIXER_VERSION_MAJOR) - unset(SDL2_MIXER_VERSION_MINOR) - unset(SDL2_MIXER_VERSION_PATCH) -endif() - -set(SDL2_MIXER_LIBRARIES ${SDL2_MIXER_LIBRARY}) -set(SDL2_MIXER_INCLUDE_DIRS ${SDL2_MIXER_INCLUDE_DIR}) - -include(FindPackageHandleStandardArgs) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_mixer - REQUIRED_VARS SDL2_MIXER_LIBRARIES SDL2_MIXER_INCLUDE_DIRS - VERSION_VAR SDL2_MIXER_VERSION_STRING) - -# for backward compatibility -set(SDLMIXER_LIBRARY ${SDL2_MIXER_LIBRARIES}) -set(SDLMIXER_INCLUDE_DIR ${SDL2_MIXER_INCLUDE_DIRS}) -set(SDLMIXER_FOUND ${SDL2_MIXER_FOUND}) - -mark_as_advanced(SDL2_MIXER_LIBRARY SDL2_MIXER_INCLUDE_DIR) diff --git a/cmake/FindSDL2_ttf.cmake b/cmake/FindSDL2_ttf.cmake deleted file mode 100644 index 4b0774dd7..000000000 --- a/cmake/FindSDL2_ttf.cmake +++ /dev/null @@ -1,99 +0,0 @@ -# Locate SDL_ttf library -# -# This module defines: -# -# :: -# -# SDL2_TTF_LIBRARIES, the name of the library to link against -# SDL2_TTF_INCLUDE_DIRS, where to find the headers -# SDL2_TTF_FOUND, if false, do not try to link against -# SDL2_TTF_VERSION_STRING - human-readable string containing the version of SDL_ttf -# -# -# -# For backward compatibility the following variables are also set: -# -# :: -# -# SDLTTF_LIBRARY (same value as SDL2_TTF_LIBRARIES) -# SDLTTF_INCLUDE_DIR (same value as SDL2_TTF_INCLUDE_DIRS) -# SDLTTF_FOUND (same value as SDL2_TTF_FOUND) -# -# -# -# $SDLDIR is an environment variable that would correspond to the -# ./configure --prefix=$SDLDIR used in building SDL. -# -# Created by Eric Wing. This was influenced by the FindSDL.cmake -# module, but with modifications to recognize OS X frameworks and -# additional Unix paths (FreeBSD, etc). - -#============================================================================= -# Copyright 2005-2009 Kitware, Inc. -# Copyright 2012 Benjamin Eikel -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -find_path(SDL2_TTF_INCLUDE_DIR SDL_ttf.h - HINTS - C:/SDL_ttf - ENV SDL2TTFDIR - ENV SDL2DIR - PATH_SUFFIXES SDL2 - # path suffixes to search inside ENV{SDLDIR} - include/SDL2 include - PATHS ${SDL2_TTF_PATH} - ) - -if (CMAKE_SIZEOF_VOID_P EQUAL 8) - set(VC_LIB_PATH_SUFFIX lib/x64) -else () - set(VC_LIB_PATH_SUFFIX lib/x86) -endif () - -find_library(SDL2_TTF_LIBRARY - NAMES SDL2_ttf - HINTS - ENV SDL2TTFDIR - ENV SDL2DIR - PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} - PATHS ${SDL2_TTF_PATH} - ) - -if (SDL2_TTF_INCLUDE_DIR AND EXISTS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h") - file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+[0-9]+$") - string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_MAJOR "${SDL2_TTF_VERSION_MAJOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_MINOR "${SDL2_TTF_VERSION_MINOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_PATCH "${SDL2_TTF_VERSION_PATCH_LINE}") - set(SDL2_TTF_VERSION_STRING ${SDL2_TTF_VERSION_MAJOR}.${SDL2_TTF_VERSION_MINOR}.${SDL2_TTF_VERSION_PATCH}) - unset(SDL2_TTF_VERSION_MAJOR_LINE) - unset(SDL2_TTF_VERSION_MINOR_LINE) - unset(SDL2_TTF_VERSION_PATCH_LINE) - unset(SDL2_TTF_VERSION_MAJOR) - unset(SDL2_TTF_VERSION_MINOR) - unset(SDL2_TTF_VERSION_PATCH) -endif () - -set(SDL2_TTF_LIBRARIES ${SDL2_TTF_LIBRARY}) -set(SDL2_TTF_INCLUDE_DIRS ${SDL2_TTF_INCLUDE_DIR}) - -include(FindPackageHandleStandardArgs) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_ttf - REQUIRED_VARS SDL2_TTF_LIBRARIES SDL2_TTF_INCLUDE_DIRS - VERSION_VAR SDL2_TTF_VERSION_STRING) - -# for backward compatibility -set(SDLTTF_LIBRARY ${SDL2_TTF_LIBRARIES}) -set(SDLTTF_INCLUDE_DIR ${SDL2_TTF_INCLUDE_DIRS}) -set(SDLTTF_FOUND ${SDL2_TTF_FOUND}) From f5e8d9d9460c023a375bd6b1b9fd3377d646c78e Mon Sep 17 00:00:00 2001 From: Albin Johansson Date: Fri, 7 Jun 2024 21:47:07 +0200 Subject: [PATCH 06/34] Add download script for test assets --- scripts/centurion.py | 30 +++++++++++++++ scripts/download_assets.py | 76 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 scripts/centurion.py create mode 100644 scripts/download_assets.py diff --git a/scripts/centurion.py b/scripts/centurion.py new file mode 100644 index 000000000..83793873a --- /dev/null +++ b/scripts/centurion.py @@ -0,0 +1,30 @@ +# Copyright (C) 2019-2024 Albin Johansson (MIT License) + +import os +import shutil +import urllib.request + + +def copy_file(src: str, dst: str): + if os.path.isfile(src): + print(f"Copying {src} to {dst}") + shutil.copy(src, dst) + else: + print(f"ERROR: could not copy missing file {src}") + + +def download_file(url: str, outfile: str): + print(f"Downloading {url} to {outfile}") + + opener = urllib.request.build_opener() + opener.addheaders = [("User-agent", "Mozilla/5.0")] + + urllib.request.install_opener(opener) + urllib.request.urlretrieve(url, outfile) + + +def download_and_extract_archive(url: str, archive_name: str, extract_dir: str): + download_file(url, archive_name) + + print(f"Extracting {archive_name} to {extract_dir}") + shutil.unpack_archive(archive_name, extract_dir) diff --git a/scripts/download_assets.py b/scripts/download_assets.py new file mode 100644 index 000000000..12c51ce79 --- /dev/null +++ b/scripts/download_assets.py @@ -0,0 +1,76 @@ +# Copyright (C) 2019-2024 Albin Johansson (MIT License) + +import argparse +import centurion +import os +import sys + +PNG_FILE_URL = "https://dummyimage.com/128x96.png" +MP3_FILE_URL = "https://opengameart.org/sites/default/files/the_field_of_dreams.mp3" + +WAV_ZIP_URL = "https://opengameart.org/sites/default/files/UI_SFX_Set.zip" +TTF_ZIP_URL = "https://dl.dafont.com/dl/?f=daniel" + + +def _download_file_if_missing(url: str, outfile: str): + try: + if not os.path.exists(outfile): + centurion.download_file(url, outfile) + else: + print(f"'{outfile}' already exists, skipping download") + except IOError: + print(f"ERROR: could not download {url}") + + +def _download_archive_if_missing(url: str, archive_name: str, extract_dir: str): + if not os.path.isdir(extract_dir): + centurion.download_and_extract_archive(url, archive_name, extract_dir) + else: + print(f"Archive '{archive_name}' already extracted") + + +def _parse_args() -> argparse.Namespace: + parser = argparse.ArgumentParser() + parser.add_argument("--outdir", metavar="", type=str, required=True, help="The output directory") + + arguments: argparse.Namespace + try: + arguments = parser.parse_args() + except argparse.ArgumentError or argparse.ArgumentTypeError: + parser.print_help() + sys.exit(-1) + + return arguments + + +def main(): + arguments = _parse_args() + output_dir = arguments.outdir + + if not os.path.isdir(output_dir): + print(f"Creating directory '{output_dir}'") + os.mkdir(output_dir) + + if not os.path.isdir(".cache"): + os.mkdir(".cache") + + png_file = ".cache/test.png" + _download_file_if_missing(PNG_FILE_URL, png_file) + + mp3_file = ".cache/test.mp3" + _download_file_if_missing(MP3_FILE_URL, mp3_file) + + ttf_file = ".cache/ttf/daniel.ttf" + _download_archive_if_missing(TTF_ZIP_URL, ".cache/ttf.zip", ".cache/ttf") + + wav_file = ".cache/wav/click3.wav" + _download_archive_if_missing(WAV_ZIP_URL, ".cache/wav.zip", ".cache/wav") + + centurion.copy_file(png_file, f"{output_dir}/test.png") + centurion.copy_file(ttf_file, f"{output_dir}/test.ttf") + centurion.copy_file(mp3_file, f"{output_dir}/test.mp3") + centurion.copy_file(wav_file, f"{output_dir}/test.wav") + + +if __name__ == "__main__": + main() From 7df25d4f9ae6c71d890f63200eba3f286fdb468c Mon Sep 17 00:00:00 2001 From: Albin Johansson Date: Fri, 7 Jun 2024 21:47:46 +0200 Subject: [PATCH 07/34] Remove old examples --- examples/CMakeLists.txt | 29 ---- examples/basic-rendering/CMakeLists.txt | 6 - examples/basic-rendering/demo.cpp | 74 --------- examples/dynamic-configuration/CMakeLists.txt | 6 - examples/dynamic-configuration/demo.cpp | 15 -- examples/event-dispatcher/CMakeLists.txt | 6 - examples/event-dispatcher/demo.cpp | 75 --------- examples/event-handler/CMakeLists.txt | 6 - examples/event-handler/demo.cpp | 69 -------- examples/font/CMakeLists.txt | 6 - examples/font/demo.cpp | 69 -------- examples/message-box/CMakeLists.txt | 6 - examples/message-box/demo.cpp | 32 ---- examples/minimal-program/CMakeLists.txt | 6 - examples/minimal-program/demo.cpp | 13 -- examples/music/CMakeLists.txt | 6 - examples/music/demo.cpp | 152 ------------------ examples/responsive-window/CMakeLists.txt | 6 - examples/responsive-window/demo.cpp | 41 ----- 19 files changed, 623 deletions(-) delete mode 100644 examples/CMakeLists.txt delete mode 100644 examples/basic-rendering/CMakeLists.txt delete mode 100644 examples/basic-rendering/demo.cpp delete mode 100644 examples/dynamic-configuration/CMakeLists.txt delete mode 100644 examples/dynamic-configuration/demo.cpp delete mode 100644 examples/event-dispatcher/CMakeLists.txt delete mode 100644 examples/event-dispatcher/demo.cpp delete mode 100644 examples/event-handler/CMakeLists.txt delete mode 100644 examples/event-handler/demo.cpp delete mode 100644 examples/font/CMakeLists.txt delete mode 100644 examples/font/demo.cpp delete mode 100644 examples/message-box/CMakeLists.txt delete mode 100644 examples/message-box/demo.cpp delete mode 100644 examples/minimal-program/CMakeLists.txt delete mode 100644 examples/minimal-program/demo.cpp delete mode 100644 examples/music/CMakeLists.txt delete mode 100644 examples/music/demo.cpp delete mode 100644 examples/responsive-window/CMakeLists.txt delete mode 100644 examples/responsive-window/demo.cpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt deleted file mode 100644 index 9bf373408..000000000 --- a/examples/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -project(centurion-examples CXX) - -# Define macro for the examples with the path to the resources to avoid copying the resources -add_compile_definitions(RESOURCE_DIR="${CEN_RESOURCES_DIR}/") - -function(cen_add_example target) - target_include_directories(${target} PRIVATE ${CEN_SOURCE_DIR}) - - cen_include_sdl_headers(${target}) - cen_link_sdl_libs(${target}) - - cen_set_basic_compiler_options(${target}) - - if (WIN32) - cen_copy_directory_post_build(${target} ${CEN_BINARIES_DIR} ${CMAKE_CURRENT_BINARY_DIR}) - endif () -endfunction() - -add_subdirectory(basic-rendering) -add_subdirectory(dynamic-configuration) -add_subdirectory(event-dispatcher) -add_subdirectory(event-handler) -add_subdirectory(font) -add_subdirectory(message-box) -add_subdirectory(minimal-program) -add_subdirectory(music) -add_subdirectory(responsive-window) diff --git a/examples/basic-rendering/CMakeLists.txt b/examples/basic-rendering/CMakeLists.txt deleted file mode 100644 index 82d80a9bb..000000000 --- a/examples/basic-rendering/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -project(centurion-examples-basic-rendering CXX) - -add_executable(ex-basic-rendering demo.cpp) -cen_add_example(ex-basic-rendering) \ No newline at end of file diff --git a/examples/basic-rendering/demo.cpp b/examples/basic-rendering/demo.cpp deleted file mode 100644 index 2db98d503..000000000 --- a/examples/basic-rendering/demo.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include - -int main(int, char**) -{ - const cen::sdl sdl; - const cen::img img; - const cen::ttf ttf; - - // Create a window and an associated renderer - cen::window window; - cen::renderer renderer = window.make_renderer(); - - // Here we assume the existence of an image and font - const cen::texture image = renderer.make_texture(RESOURCE_DIR "panda.png"); - const cen::font font {RESOURCE_DIR "daniel.ttf", 36}; - - // Render a string to a texture, which in turn can be rendered to our render target - auto text = renderer.make_texture(font.render_blended("Hello world!", cen::colors::black)); - - window.show(); - - bool running = true; - while (running) { - cen::event_handler handler; - while (handler.poll()) { - if (handler.is(cen::event_type::quit)) { - running = false; - break; - } - } - - // Clear our render target with an arbitrary color - renderer.clear_with(cen::colors::light_coral); - - // Draw a filled circle - renderer.set_color(cen::colors::red); - renderer.fill_circle(cen::fpoint {150, 150}, 75); - - // Draw an outlined circle - renderer.set_color(cen::colors::cyan); - renderer.draw_circle(cen::fpoint {350, 275}, 50); - - // Draw a filled rectangle - renderer.set_color(cen::colors::lime_green); - renderer.fill_rect(cen::frect {25.0, 500.0, 125.0, 75.0}); - - // Draw an outlined rectangle - renderer.set_color(cen::colors::khaki); - renderer.draw_rect(cen::frect {550.0, 50.0, 140.0, 60.0}); - - // Draw a line between two points - renderer.set_color(cen::colors::forest_green); - renderer.draw_line(cen::fpoint {240.0, 340.0}, cen::fpoint {360.0, 460.0}); - - // Render the image along with the text (also in the form of a texture) - renderer.render(image, cen::fpoint {600.0, 450.0}); - renderer.render(text, cen::fpoint {450.0, 230.0}); - -#if SDL_VERSION_ATLEAST(2, 0, 18) - // Render a triangle, using the low level "geometry" rendering API - const SDL_Vertex vertices[] = {{{650, 400}, cen::colors::red.get(), {}}, - {{410, 310}, cen::colors::lime.get(), {}}, - {{450, 550}, cen::colors::blue.get(), {}}}; - renderer.render_geo(vertices); -#endif // SDL_VERSION_ATLEAST(2, 0, 18) - - // Apply our draw calls to the render target (the window) - renderer.present(); - } - - window.hide(); - - return 0; -} \ No newline at end of file diff --git a/examples/dynamic-configuration/CMakeLists.txt b/examples/dynamic-configuration/CMakeLists.txt deleted file mode 100644 index 6872b321e..000000000 --- a/examples/dynamic-configuration/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -project(centurion-examples-dynamic-configuration CXX) - -add_executable(ex-dynamic-configuration demo.cpp) -cen_add_example(ex-dynamic-configuration) \ No newline at end of file diff --git a/examples/dynamic-configuration/demo.cpp b/examples/dynamic-configuration/demo.cpp deleted file mode 100644 index 1f381c747..000000000 --- a/examples/dynamic-configuration/demo.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include - -int main(int, char**) -{ - cen::sdl_cfg cfg; // Assumes the standard configuration values by default - cfg.flags = SDL_INIT_EVERYTHING & ~SDL_INIT_AUDIO; // No core audio support - - const cen::sdl sdl {cfg}; - const cen::img img; - const cen::ttf ttf; - - // Initialized SDL with no audio support, and all extension libraries except SDL_mixer - - return 0; -} \ No newline at end of file diff --git a/examples/event-dispatcher/CMakeLists.txt b/examples/event-dispatcher/CMakeLists.txt deleted file mode 100644 index 8b481ca1c..000000000 --- a/examples/event-dispatcher/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -project(centurion-examples-event-dispatcher CXX) - -add_executable(ex-event-dispatcher demo.cpp) -cen_add_example(ex-event-dispatcher) \ No newline at end of file diff --git a/examples/event-dispatcher/demo.cpp b/examples/event-dispatcher/demo.cpp deleted file mode 100644 index fd11e76a4..000000000 --- a/examples/event-dispatcher/demo.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include - -namespace { - -// Here we specify that we want to subscribe to four different kinds of events -using event_dispatcher = cen::event_dispatcher; - -void on_mouse_button_event(const cen::mouse_button_event& event) -{ - cen::log_info("mouse_button_event (x: %i, y: %i)", event.x(), event.y()); -} - -// Our AAA game class -class aaa_game final { - public: - aaa_game() - { - // Member function handlers - m_dispatcher.bind().to<&aaa_game::on_quit_event>(this); - m_dispatcher.bind().to<&aaa_game::on_window_event>(this); - - // Lambda handler - m_dispatcher.bind().to( - [](const cen::keyboard_event&) { cen::log_info("keyboard_event"); }); - - // Free function handler - m_dispatcher.bind().to<&on_mouse_button_event>(); - } - - auto run() -> int - { - m_window.show(); - - while (m_running) { - // All we need to do each frame to handle events is to poll the event dispatcher - m_dispatcher.poll(); - - // Game logic goes here... - } - - m_window.hide(); - return 0; - } - - private: - cen::window m_window; - event_dispatcher m_dispatcher; - bool m_running {true}; - - // Invoked for each quit event - void on_quit_event(const cen::quit_event&) - { - cen::log_info("quit_event"); - m_running = false; - } - - // Invoked for each window event - void on_window_event(const cen::window_event&) {} -}; - -} // namespace - -int main(int, char**) -{ - const cen::sdl sdl; - const cen::img img; - const cen::mix mix; - const cen::ttf ttf; - - aaa_game game; - return game.run(); -} \ No newline at end of file diff --git a/examples/event-handler/CMakeLists.txt b/examples/event-handler/CMakeLists.txt deleted file mode 100644 index a24e753e9..000000000 --- a/examples/event-handler/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -project(centurion-examples-event-handler CXX) - -add_executable(ex-event-handler demo.cpp) -cen_add_example(ex-event-handler) \ No newline at end of file diff --git a/examples/event-handler/demo.cpp b/examples/event-handler/demo.cpp deleted file mode 100644 index 80b1d9c40..000000000 --- a/examples/event-handler/demo.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include // array -#include -#include // size_t -#include // optional - -namespace { - -constexpr std::array colors = {cen::colors::hot_pink, - cen::colors::dark_olive_green, - cen::colors::dark_turquoise}; - -} // namespace - -int main(int, char**) -{ - const cen::sdl sdl; - - cen::window window {"event_handler demo"}; - cen::renderer renderer = window.make_renderer(); - - window.show(); - - // Create our event handler, which provides our event management API - cen::event_handler handler; - - std::size_t colorIndex = 0; - std::optional mousePos; - - bool running = true; - while (running) { - // Go through the event queue, handling the different pending events - while (handler.poll()) { - if (handler.is()) { - running = false; - break; - } - else if (handler.is(cen::event_type::key_down)) { - // We received a keyboard event, so get the internal event representation. - const auto& keyboardEvent = handler.get(); - if (!keyboardEvent.repeated()) { - colorIndex = (colorIndex + 1u) % colors.size(); - } - } - else if (const auto* buttonEvent = handler.try_get()) { - if (buttonEvent->pressed()) { - mousePos = buttonEvent->position(); - } - } - } - - renderer.clear_with(colors.at(colorIndex)); - - if (mousePos) { - renderer.set_color(colors.at((colorIndex + 1u) % colors.size())); - - cen::irect rect {*mousePos, {6, 6}}; - rect.offset_x(-3); - rect.offset_y(-3); - - renderer.fill_rect(rect); - } - - renderer.present(); - } - - window.hide(); - - return 0; -} \ No newline at end of file diff --git a/examples/font/CMakeLists.txt b/examples/font/CMakeLists.txt deleted file mode 100644 index ec241d639..000000000 --- a/examples/font/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -project(centurion-examples-font CXX) - -add_executable(ex-font demo.cpp) -cen_add_example(ex-font) \ No newline at end of file diff --git a/examples/font/demo.cpp b/examples/font/demo.cpp deleted file mode 100644 index c1de78807..000000000 --- a/examples/font/demo.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include - -#define ANSWER(Expr) (Expr) ? "Yes" : "No" - -int main(int, char**) -{ - // The font API requires the SDL_ttf extension - const cen::sdl sdl; - const cen::ttf ttf; - - cen::font font {RESOURCE_DIR "daniel.ttf", 12}; - - cen::log_info("The font size is %i", font.size()); - - if (const char* family = font.family_name()) { - cen::log_info("The font family is '%s'", family); - } - - if (const char* style = font.style_name()) { - cen::log_info("The font style is '%s'", style); - } - - // Font queries - cen::log_info("Is the font fixed width? %s", ANSWER(font.is_fixed_width())); - cen::log_info("Font height: %i", font.height()); - cen::log_info("Font ascent: %i", font.ascent()); - cen::log_info("Font descent: %i", font.descent()); - - // Font styling - font.set_italic(true); - font.set_bold(false); - font.set_strikethrough(false); - font.set_kerning(true); - font.set_underlined(false); - - cen::log_info("Is the font bold? %s", ANSWER(font.is_bold())); - cen::log_info("Is the font italic? %s", ANSWER(font.is_italic())); - cen::log_info("Is the font strikethrough? %s", ANSWER(font.is_strikethrough())); - cen::log_info("Is the font underlined? %s", ANSWER(font.is_underlined())); - cen::log_info("Is kerning enabled? %s", ANSWER(font.has_kerning())); - - // Glyph availability checks - const cen::unicode_t glyph = 'A'; - cen::log_info("Is the glyph '%c' provided? %s", - glyph, - ANSWER(font.is_glyph_provided(glyph))); - - // Glyph metrics - if (const auto metrics = font.get_metrics(glyph)) { - cen::log_info("Metrics for glyph '%c'...", glyph); - cen::log_info(" Glyph advance: %i", metrics->advance); - cen::log_info(" Glyph maximum x-offset: %i", metrics->max_x); - cen::log_info(" Glyph maximum y-offset: %i", metrics->max_y); - cen::log_info(" Glyph minimum x-offset: %i", metrics->min_x); - cen::log_info(" Glyph minimum y-offset: %i", metrics->min_y); - } - - // Calculate the size of a rendered string - const char* str = "foobar"; - if (const auto size = font.calc_size(str)) { - cen::log_info("The size of '%s' is (%i, %i)", str, size->width, size->height); - } - - // Render text to surface - const cen::surface surface = font.render_blended(str, cen::colors::white); - cen::log_info("Rendered surface size: (%i, %i)", surface.width(), surface.height()); - - return 0; -} \ No newline at end of file diff --git a/examples/message-box/CMakeLists.txt b/examples/message-box/CMakeLists.txt deleted file mode 100644 index b869f496c..000000000 --- a/examples/message-box/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -project(centurion-examples-message-box CXX) - -add_executable(ex-message-box demo.cpp) -cen_add_example(ex-message-box) \ No newline at end of file diff --git a/examples/message-box/demo.cpp b/examples/message-box/demo.cpp deleted file mode 100644 index b3fdd6a64..000000000 --- a/examples/message-box/demo.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include - -int main(int, char**) -{ - const cen::sdl sdl; - - cen::message_box mb; - mb.set_title("This is a message box"); - mb.set_message("May I please have your attention?"); - - mb.set_type(cen::message_box_type::warning); - mb.set_button_order(cen::message_box_button_order::left_to_right); - - const cen::message_box::button_id yes = 1; - const cen::message_box::button_id no = 2; - mb.add_button(yes, "Yes"); - mb.add_button(no, "No"); - - const auto button = mb.show(); - if (button.has_value()) { - cen::log_info("Pressed message box button %i!", *button); - } - - if (button == yes) { - // If all you need is a simple message box, you can use the static show functions. - cen::message_box::show("This is a simple message box", - "I was opened with a single line of code!", - cen::message_box_type::information); - } - - return 0; -} \ No newline at end of file diff --git a/examples/minimal-program/CMakeLists.txt b/examples/minimal-program/CMakeLists.txt deleted file mode 100644 index b4ed72bdf..000000000 --- a/examples/minimal-program/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -project(centurion-examples-minimal-program CXX) - -add_executable(ex-minimal-program demo.cpp) -cen_add_example(ex-minimal-program) \ No newline at end of file diff --git a/examples/minimal-program/demo.cpp b/examples/minimal-program/demo.cpp deleted file mode 100644 index edaa1a06b..000000000 --- a/examples/minimal-program/demo.cpp +++ /dev/null @@ -1,13 +0,0 @@ -#include - -int main(int, char**) // The signature of main must be equivalent to this! -{ - const cen::sdl sdl; - const cen::img img; - const cen::mix mix; - const cen::ttf ttf; - - // The core SDL library along with the extension libraries are now initialized! - - return 0; -} \ No newline at end of file diff --git a/examples/music/CMakeLists.txt b/examples/music/CMakeLists.txt deleted file mode 100644 index e2abe0f7c..000000000 --- a/examples/music/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -project(centurion-examples-music CXX) - -add_executable(ex-music demo.cpp) -cen_add_example(ex-music) \ No newline at end of file diff --git a/examples/music/demo.cpp b/examples/music/demo.cpp deleted file mode 100644 index 38b56f8c5..000000000 --- a/examples/music/demo.cpp +++ /dev/null @@ -1,152 +0,0 @@ -#include -#include // optional - -namespace { - -using event_dispatcher = cen::event_dispatcher; - -constexpr cen::iarea window_size = cen::window::default_size(); - -constexpr auto msg_zero = "\"0\" to play the click one time."; -constexpr auto msg_one = "\"1\" to play the click one time."; -constexpr auto msg_two = "\"2\" to play the click two times."; -constexpr auto msg_nine = "\"9\" to play the click forever."; -constexpr auto msg_fade = "\"F\" to fade in the music over 5 seconds."; -constexpr auto msg_halt = "\"ESC\" to halt the music."; -constexpr auto msg_playing = "Music is playing!"; -constexpr auto msg_fading = "Music is fading!"; -constexpr auto msg_no_music = "No music is playing"; - -class music_example final { - public: - music_example() - : mWindow {"Music example", - window_size, - cen::window::hidden | cen::window::allow_high_dpi} - , mRenderer {mWindow.make_renderer()} - , mFont {RESOURCE_DIR "fira_code.ttf", 16} - , mSong {RESOURCE_DIR "hidden_pond.mp3"} - , mClick {RESOURCE_DIR "click.wav"} - { - mRenderer.set_logical_size(window_size); - - mDispatcher.bind().to<&music_example::on_quit_event>(this); - mDispatcher.bind().to<&music_example::on_keyboard_event>(this); - - load_messages(); - } - - auto run() -> int - { - mWindow.show(); - - while (m_running) { - mDispatcher.poll(); - render(); - } - - mWindow.hide(); - return 0; - } - - private: - cen::window mWindow; - cen::renderer mRenderer; - cen::font mFont; - event_dispatcher mDispatcher; - cen::music mSong; - cen::music mClick; - bool m_running {true}; - - std::vector mInstructions; - std::optional mTexPlayingMusic; - std::optional mTexFadingMusic; - std::optional mTexNoMusic; - - void load_messages() - { - const auto load = [this](const char* msg, cen::color fg = cen::colors::white) { - return mRenderer.make_texture(mFont.render_blended(msg, fg)); - }; - - mInstructions.push_back(load(msg_zero)); - mInstructions.push_back(load(msg_one)); - mInstructions.push_back(load(msg_two)); - mInstructions.push_back(load(msg_nine)); - mInstructions.push_back(load(msg_fade)); - mInstructions.push_back(load(msg_halt)); - - mTexPlayingMusic = load(msg_playing, cen::colors::lime_green); - mTexFadingMusic = load(msg_fading, cen::colors::hot_pink); - mTexNoMusic = load(msg_no_music, cen::colors::red); - } - - void on_quit_event(const cen::quit_event&) { m_running = false; } - - void on_keyboard_event(const cen::keyboard_event& event) - { - if (event.released()) { - if (event.is_active(cen::scancodes::zero)) { - mClick.play(0); - } - else if (event.is_active(cen::scancodes::one)) { - mClick.play(1); - } - else if (event.is_active(cen::scancodes::two)) { - mClick.play(2); - } - else if (event.is_active(cen::scancodes::nine)) { - mClick.play(cen::music::forever); - } - else if (event.is_active(cen::scancodes::f)) { - mSong.fade_in(cen::music::ms_type {5'000}); - } - else if (event.is_active(cen::scancodes::escape)) { - cen::music::halt(); - } - } - } - - void render() - { - auto position_of = [y = 50](const cen::texture& texture) mutable { - const auto x = (window_size.width - texture.width()) / 2; - const auto oldY = y; - - y += 25; - return cen::ipoint {x, oldY}; - }; - - mRenderer.clear_with(cen::colors::steel_blue); - - for (const auto& texture : mInstructions) { - mRenderer.render(texture, position_of(texture)); - } - - constexpr cen::ipoint offset {0, 25}; - if (cen::music::is_playing() && !cen::music::is_fading()) { - mRenderer.render(*mTexPlayingMusic, position_of(*mTexPlayingMusic) + offset); - } - else if (cen::music::is_fading()) { - mRenderer.render(*mTexFadingMusic, position_of(*mTexFadingMusic) + offset); - } - else { - mRenderer.render(*mTexNoMusic, position_of(*mTexNoMusic) + offset); - } - - mRenderer.present(); - } -}; - -} // namespace - -auto main(int, char**) -> int -{ - const cen::sdl sdl; - const cen::img img; - const cen::mix mix; - const cen::ttf ttf; - - music_example example; - return example.run(); -} diff --git a/examples/responsive-window/CMakeLists.txt b/examples/responsive-window/CMakeLists.txt deleted file mode 100644 index 3a4188ec9..000000000 --- a/examples/responsive-window/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -project(centurion-examples-responsive-window CXX) - -add_executable(ex-responsive-window demo.cpp) -cen_add_example(ex-responsive-window) \ No newline at end of file diff --git a/examples/responsive-window/demo.cpp b/examples/responsive-window/demo.cpp deleted file mode 100644 index 4a57f5f05..000000000 --- a/examples/responsive-window/demo.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include - -int main(int, char**) -{ - // Initialize the SDL libraries - const cen::sdl sdl; - const cen::img img; - const cen::mix mix; - const cen::ttf ttf; - - // Create a window and an associated renderer - cen::window window; - cen::renderer renderer = window.make_renderer(); - - // Make sure our window is visible - window.show(); - - cen::event_handler event; - bool running = true; - - while (running) { - while (event.poll()) { - // Check if the user wants to quit the application - if (event.is()) { - running = false; - break; - } - } - - renderer.clear_with(cen::colors::coral); - - // Miscellaneous rendering code goes here... - - renderer.present(); - } - - // Make the window invisible again, this might not be necessary, but it doesn't hurt - window.hide(); - - return 0; -} \ No newline at end of file From 8a671f789bef8e12cde2ce637384dcba6b739241 Mon Sep 17 00:00:00 2001 From: Albin Johansson Date: Fri, 7 Jun 2024 21:48:15 +0200 Subject: [PATCH 08/34] Remove old unit tests --- test/unit-tests/CMakeLists.txt | 261 ------- test/unit-tests/audio/fade_status_test.cpp | 46 -- test/unit-tests/audio/music_test.cpp | 284 -------- test/unit-tests/audio/music_type_test.cpp | 58 -- test/unit-tests/audio/sound_effect_test.cpp | 172 ----- test/unit-tests/common/compiler_test.cpp | 45 -- test/unit-tests/common/exception_test.cpp | 73 -- test/unit-tests/common/features_test.cpp | 58 -- test/unit-tests/common/log_category_test.cpp | 63 -- test/unit-tests/common/log_priority_test.cpp | 55 -- test/unit-tests/common/log_test.cpp | 92 --- test/unit-tests/common/math/area_test.cpp | 163 ----- test/unit-tests/common/math/point_test.cpp | 239 ------ test/unit-tests/common/math/rect_test.cpp | 686 ------------------ test/unit-tests/common/math/vector3_test.cpp | 122 ---- .../common/memory/simd_block_test.cpp | 44 -- test/unit-tests/common/result_test.cpp | 49 -- test/unit-tests/common/sdl_string_test.cpp | 63 -- test/unit-tests/common/to_underlying_test.cpp | 57 -- test/unit-tests/common/version_test.cpp | 143 ---- .../unit-tests/concurrency/condition_test.cpp | 66 -- .../concurrency/lock_status_test.cpp | 47 -- test/unit-tests/concurrency/mutex_test.cpp | 52 -- .../concurrency/scoped_lock_test.cpp | 38 - .../unit-tests/concurrency/semaphore_test.cpp | 79 -- .../concurrency/thread_priority_test.cpp | 49 -- test/unit-tests/concurrency/thread_test.cpp | 186 ----- test/unit-tests/concurrency/try_lock_test.cpp | 60 -- test/unit-tests/detail/address_of_test.cpp | 53 -- test/unit-tests/detail/clamp_test.cpp | 42 -- test/unit-tests/detail/from_string_test.cpp | 45 -- test/unit-tests/detail/max_test.cpp | 42 -- test/unit-tests/detail/min_test.cpp | 42 -- .../detail/owner_handle_api_test.cpp | 110 --- .../event/audio/audio_device_event_test.cpp | 65 -- .../controller/controller_axis_event_test.cpp | 72 -- .../controller_button_event_test.cpp | 77 -- .../controller_device_event_test.cpp | 52 -- .../controller_sensor_event_test.cpp | 87 --- .../controller_touchpad_event_test.cpp | 113 --- test/unit-tests/event/event_base_test.cpp | 86 --- .../event/event_dispatcher_test.cpp | 132 ---- test/unit-tests/event/event_handler_test.cpp | 213 ------ .../event/event_handler_type_check_test.cpp | 216 ------ test/unit-tests/event/event_type_test.cpp | 214 ------ .../gesture/dollar_gesture_event_test.cpp | 156 ---- .../gesture/multi_gesture_event_test.cpp | 144 ---- .../event/joystick/joy_axis_event_test.cpp | 72 -- .../event/joystick/joy_ball_event_test.cpp | 82 --- .../event/joystick/joy_battery_event_test.cpp | 66 -- .../event/joystick/joy_button_event_test.cpp | 79 -- .../event/joystick/joy_device_event_test.cpp | 52 -- .../event/joystick/joy_hat_event_test.cpp | 60 -- .../event/joystick/joy_hat_position_test.cpp | 61 -- .../event/misc/display_event_id_test.cpp | 55 -- .../event/misc/display_event_test.cpp | 86 --- .../unit-tests/event/misc/drop_event_test.cpp | 78 -- .../event/misc/keyboard_event_test.cpp | 202 ------ .../unit-tests/event/misc/quit_event_test.cpp | 42 -- .../event/misc/sensor_event_test.cpp | 69 -- .../event/misc/touch_finger_event_test.cpp | 258 ------- .../unit-tests/event/misc/user_event_test.cpp | 97 --- .../event/mouse/mouse_button_event_test.cpp | 117 --- .../event/mouse/mouse_motion_event_test.cpp | 117 --- .../mouse/mouse_wheel_direction_test.cpp | 47 -- .../event/mouse/mouse_wheel_event_test.cpp | 114 --- .../event/text/text_editing_event_test.cpp | 123 ---- .../text/text_editing_ext_event_test.cpp | 72 -- .../event/text/text_input_event_test.cpp | 69 -- .../event/window/window_event_id_test.cpp | 87 --- .../event/window/window_event_test.cpp | 77 -- test/unit-tests/filesystem/base_path_test.cpp | 32 - test/unit-tests/filesystem/file_mode_test.cpp | 52 -- test/unit-tests/filesystem/file_test.cpp | 136 ---- test/unit-tests/filesystem/file_type_test.cpp | 53 -- .../filesystem/preferred_path_test.cpp | 33 - test/unit-tests/filesystem/seek_mode_test.cpp | 47 -- test/unit-tests/input/button_state_test.cpp | 45 -- .../input/controller/controller_axis_test.cpp | 63 -- .../controller/controller_bind_type_test.cpp | 51 -- .../controller/controller_button_test.cpp | 107 --- .../controller_mapping_result_test.cpp | 42 -- .../input/controller/controller_test.cpp | 75 -- .../input/controller/controller_type_test.cpp | 79 -- .../input/joystick/hat_state_test.cpp | 59 -- .../input/joystick/joystick_power_test.cpp | 56 -- .../input/joystick/joystick_test.cpp | 90 --- .../input/joystick/joystick_type_test.cpp | 62 -- .../input/keyboard/key_code_tests.cpp | 323 --------- .../input/keyboard/key_modifier_test.cpp | 136 ---- .../input/keyboard/keyboard_test.cpp | 111 --- .../input/keyboard/scan_code_tests.cpp | 290 -------- test/unit-tests/input/mouse/cursor_test.cpp | 117 --- .../input/mouse/mouse_button_test.cpp | 51 -- test/unit-tests/input/mouse/mouse_test.cpp | 70 -- .../input/mouse/system_cursor_test.cpp | 71 -- test/unit-tests/input/sensor/sensor_test.cpp | 43 -- .../input/sensor/sensor_type_test.cpp | 50 -- .../input/touch/touch_device_type_test.cpp | 52 -- test/unit-tests/input/touch/touch_test.cpp | 42 -- .../message-box/mb_button_flags_test.cpp | 35 - .../message-box/mb_button_order_test.cpp | 52 -- .../message-box/mb_color_scheme.cpp | 57 -- .../message-box/mb_color_type_test.cpp | 58 -- test/unit-tests/message-box/mb_type_test.cpp | 48 -- .../message-box/message_box_test.cpp | 124 ---- test/unit-tests/serialization_utils.hpp | 53 -- test/unit-tests/system/clipboard_test.cpp | 46 -- test/unit-tests/system/counter_test.cpp | 56 -- test/unit-tests/system/endian/endian_test.cpp | 109 --- test/unit-tests/system/locale/locale_test.cpp | 47 -- test/unit-tests/system/platform_id_test.cpp | 43 -- test/unit-tests/system/platform_test.cpp | 75 -- test/unit-tests/system/power/battery_test.cpp | 96 --- .../system/power/power_state_test.cpp | 52 -- test/unit-tests/system/ram_test.cpp | 37 - test/unit-tests/system/shared_object_test.cpp | 32 - test/unit-tests/test_main.cpp | 45 -- .../unit-tests/text/font/font_bundle_test.cpp | 79 -- test/unit-tests/text/font/font_cache_test.cpp | 239 ------ test/unit-tests/text/font/font_hint_test.cpp | 57 -- test/unit-tests/text/font/font_test.cpp | 371 ---------- .../text/font/wrap_alignment_test.cpp | 47 -- .../text/unicode/unicode_string_test.cpp | 322 -------- test/unit-tests/typed_test_macros.hpp | 53 -- .../video/blend-mode/blend_factor_test.cpp | 73 -- .../video/blend-mode/blend_mode_test.cpp | 60 -- .../video/blend-mode/blend_op_test.cpp | 51 -- test/unit-tests/video/color_test.cpp | 405 ----------- .../video/display/display_mode_test.cpp | 79 -- .../unit-tests/video/display/display_test.cpp | 110 --- .../video/display/orientation_test.cpp | 57 -- .../video/opengl/gl_attribute_test.cpp | 118 --- .../video/opengl/gl_swap_interval_test.cpp | 48 -- test/unit-tests/video/pixels/palette_test.cpp | 92 --- .../video/pixels/pixel_format_info_test.cpp | 109 --- .../video/pixels/pixel_format_test.cpp | 169 ----- .../video/render/graphics_drivers_test.cpp | 37 - .../video/render/renderer_handle_test.cpp | 79 -- .../unit-tests/video/render/renderer_test.cpp | 220 ------ .../video/render/texture/scale_mode_test.cpp | 51 -- .../render/texture/texture_access_test.cpp | 47 -- .../render/texture/texture_handle_test.cpp | 70 -- .../video/render/texture/texture_test.cpp | 253 ------- .../video/surface/surface_handle_test.cpp | 41 -- .../unit-tests/video/surface/surface_test.cpp | 243 ------- .../unit-tests/video/window/flash_op_test.cpp | 51 -- .../video/window/window_flags_test.cpp | 64 -- .../video/window/window_handle_test.cpp | 61 -- test/unit-tests/video/window/window_test.cpp | 108 --- 150 files changed, 14860 deletions(-) delete mode 100644 test/unit-tests/CMakeLists.txt delete mode 100644 test/unit-tests/audio/fade_status_test.cpp delete mode 100644 test/unit-tests/audio/music_test.cpp delete mode 100644 test/unit-tests/audio/music_type_test.cpp delete mode 100644 test/unit-tests/audio/sound_effect_test.cpp delete mode 100644 test/unit-tests/common/compiler_test.cpp delete mode 100644 test/unit-tests/common/exception_test.cpp delete mode 100644 test/unit-tests/common/features_test.cpp delete mode 100644 test/unit-tests/common/log_category_test.cpp delete mode 100644 test/unit-tests/common/log_priority_test.cpp delete mode 100644 test/unit-tests/common/log_test.cpp delete mode 100644 test/unit-tests/common/math/area_test.cpp delete mode 100644 test/unit-tests/common/math/point_test.cpp delete mode 100644 test/unit-tests/common/math/rect_test.cpp delete mode 100644 test/unit-tests/common/math/vector3_test.cpp delete mode 100644 test/unit-tests/common/memory/simd_block_test.cpp delete mode 100644 test/unit-tests/common/result_test.cpp delete mode 100644 test/unit-tests/common/sdl_string_test.cpp delete mode 100644 test/unit-tests/common/to_underlying_test.cpp delete mode 100644 test/unit-tests/common/version_test.cpp delete mode 100644 test/unit-tests/concurrency/condition_test.cpp delete mode 100644 test/unit-tests/concurrency/lock_status_test.cpp delete mode 100644 test/unit-tests/concurrency/mutex_test.cpp delete mode 100644 test/unit-tests/concurrency/scoped_lock_test.cpp delete mode 100644 test/unit-tests/concurrency/semaphore_test.cpp delete mode 100644 test/unit-tests/concurrency/thread_priority_test.cpp delete mode 100644 test/unit-tests/concurrency/thread_test.cpp delete mode 100644 test/unit-tests/concurrency/try_lock_test.cpp delete mode 100644 test/unit-tests/detail/address_of_test.cpp delete mode 100644 test/unit-tests/detail/clamp_test.cpp delete mode 100644 test/unit-tests/detail/from_string_test.cpp delete mode 100644 test/unit-tests/detail/max_test.cpp delete mode 100644 test/unit-tests/detail/min_test.cpp delete mode 100644 test/unit-tests/detail/owner_handle_api_test.cpp delete mode 100644 test/unit-tests/event/audio/audio_device_event_test.cpp delete mode 100644 test/unit-tests/event/controller/controller_axis_event_test.cpp delete mode 100644 test/unit-tests/event/controller/controller_button_event_test.cpp delete mode 100644 test/unit-tests/event/controller/controller_device_event_test.cpp delete mode 100644 test/unit-tests/event/controller/controller_sensor_event_test.cpp delete mode 100644 test/unit-tests/event/controller/controller_touchpad_event_test.cpp delete mode 100644 test/unit-tests/event/event_base_test.cpp delete mode 100644 test/unit-tests/event/event_dispatcher_test.cpp delete mode 100644 test/unit-tests/event/event_handler_test.cpp delete mode 100644 test/unit-tests/event/event_handler_type_check_test.cpp delete mode 100644 test/unit-tests/event/event_type_test.cpp delete mode 100644 test/unit-tests/event/gesture/dollar_gesture_event_test.cpp delete mode 100644 test/unit-tests/event/gesture/multi_gesture_event_test.cpp delete mode 100644 test/unit-tests/event/joystick/joy_axis_event_test.cpp delete mode 100644 test/unit-tests/event/joystick/joy_ball_event_test.cpp delete mode 100644 test/unit-tests/event/joystick/joy_battery_event_test.cpp delete mode 100644 test/unit-tests/event/joystick/joy_button_event_test.cpp delete mode 100644 test/unit-tests/event/joystick/joy_device_event_test.cpp delete mode 100644 test/unit-tests/event/joystick/joy_hat_event_test.cpp delete mode 100644 test/unit-tests/event/joystick/joy_hat_position_test.cpp delete mode 100644 test/unit-tests/event/misc/display_event_id_test.cpp delete mode 100644 test/unit-tests/event/misc/display_event_test.cpp delete mode 100644 test/unit-tests/event/misc/drop_event_test.cpp delete mode 100644 test/unit-tests/event/misc/keyboard_event_test.cpp delete mode 100644 test/unit-tests/event/misc/quit_event_test.cpp delete mode 100644 test/unit-tests/event/misc/sensor_event_test.cpp delete mode 100644 test/unit-tests/event/misc/touch_finger_event_test.cpp delete mode 100644 test/unit-tests/event/misc/user_event_test.cpp delete mode 100644 test/unit-tests/event/mouse/mouse_button_event_test.cpp delete mode 100644 test/unit-tests/event/mouse/mouse_motion_event_test.cpp delete mode 100644 test/unit-tests/event/mouse/mouse_wheel_direction_test.cpp delete mode 100644 test/unit-tests/event/mouse/mouse_wheel_event_test.cpp delete mode 100644 test/unit-tests/event/text/text_editing_event_test.cpp delete mode 100644 test/unit-tests/event/text/text_editing_ext_event_test.cpp delete mode 100644 test/unit-tests/event/text/text_input_event_test.cpp delete mode 100644 test/unit-tests/event/window/window_event_id_test.cpp delete mode 100644 test/unit-tests/event/window/window_event_test.cpp delete mode 100644 test/unit-tests/filesystem/base_path_test.cpp delete mode 100644 test/unit-tests/filesystem/file_mode_test.cpp delete mode 100644 test/unit-tests/filesystem/file_test.cpp delete mode 100644 test/unit-tests/filesystem/file_type_test.cpp delete mode 100644 test/unit-tests/filesystem/preferred_path_test.cpp delete mode 100644 test/unit-tests/filesystem/seek_mode_test.cpp delete mode 100644 test/unit-tests/input/button_state_test.cpp delete mode 100644 test/unit-tests/input/controller/controller_axis_test.cpp delete mode 100644 test/unit-tests/input/controller/controller_bind_type_test.cpp delete mode 100644 test/unit-tests/input/controller/controller_button_test.cpp delete mode 100644 test/unit-tests/input/controller/controller_mapping_result_test.cpp delete mode 100644 test/unit-tests/input/controller/controller_test.cpp delete mode 100644 test/unit-tests/input/controller/controller_type_test.cpp delete mode 100644 test/unit-tests/input/joystick/hat_state_test.cpp delete mode 100644 test/unit-tests/input/joystick/joystick_power_test.cpp delete mode 100644 test/unit-tests/input/joystick/joystick_test.cpp delete mode 100644 test/unit-tests/input/joystick/joystick_type_test.cpp delete mode 100644 test/unit-tests/input/keyboard/key_code_tests.cpp delete mode 100644 test/unit-tests/input/keyboard/key_modifier_test.cpp delete mode 100644 test/unit-tests/input/keyboard/keyboard_test.cpp delete mode 100644 test/unit-tests/input/keyboard/scan_code_tests.cpp delete mode 100644 test/unit-tests/input/mouse/cursor_test.cpp delete mode 100644 test/unit-tests/input/mouse/mouse_button_test.cpp delete mode 100644 test/unit-tests/input/mouse/mouse_test.cpp delete mode 100644 test/unit-tests/input/mouse/system_cursor_test.cpp delete mode 100644 test/unit-tests/input/sensor/sensor_test.cpp delete mode 100644 test/unit-tests/input/sensor/sensor_type_test.cpp delete mode 100644 test/unit-tests/input/touch/touch_device_type_test.cpp delete mode 100644 test/unit-tests/input/touch/touch_test.cpp delete mode 100644 test/unit-tests/message-box/mb_button_flags_test.cpp delete mode 100644 test/unit-tests/message-box/mb_button_order_test.cpp delete mode 100644 test/unit-tests/message-box/mb_color_scheme.cpp delete mode 100644 test/unit-tests/message-box/mb_color_type_test.cpp delete mode 100644 test/unit-tests/message-box/mb_type_test.cpp delete mode 100644 test/unit-tests/message-box/message_box_test.cpp delete mode 100644 test/unit-tests/serialization_utils.hpp delete mode 100644 test/unit-tests/system/clipboard_test.cpp delete mode 100644 test/unit-tests/system/counter_test.cpp delete mode 100644 test/unit-tests/system/endian/endian_test.cpp delete mode 100644 test/unit-tests/system/locale/locale_test.cpp delete mode 100644 test/unit-tests/system/platform_id_test.cpp delete mode 100644 test/unit-tests/system/platform_test.cpp delete mode 100644 test/unit-tests/system/power/battery_test.cpp delete mode 100644 test/unit-tests/system/power/power_state_test.cpp delete mode 100644 test/unit-tests/system/ram_test.cpp delete mode 100644 test/unit-tests/system/shared_object_test.cpp delete mode 100644 test/unit-tests/test_main.cpp delete mode 100644 test/unit-tests/text/font/font_bundle_test.cpp delete mode 100644 test/unit-tests/text/font/font_cache_test.cpp delete mode 100644 test/unit-tests/text/font/font_hint_test.cpp delete mode 100644 test/unit-tests/text/font/font_test.cpp delete mode 100644 test/unit-tests/text/font/wrap_alignment_test.cpp delete mode 100644 test/unit-tests/text/unicode/unicode_string_test.cpp delete mode 100644 test/unit-tests/typed_test_macros.hpp delete mode 100644 test/unit-tests/video/blend-mode/blend_factor_test.cpp delete mode 100644 test/unit-tests/video/blend-mode/blend_mode_test.cpp delete mode 100644 test/unit-tests/video/blend-mode/blend_op_test.cpp delete mode 100644 test/unit-tests/video/color_test.cpp delete mode 100644 test/unit-tests/video/display/display_mode_test.cpp delete mode 100644 test/unit-tests/video/display/display_test.cpp delete mode 100644 test/unit-tests/video/display/orientation_test.cpp delete mode 100644 test/unit-tests/video/opengl/gl_attribute_test.cpp delete mode 100644 test/unit-tests/video/opengl/gl_swap_interval_test.cpp delete mode 100644 test/unit-tests/video/pixels/palette_test.cpp delete mode 100644 test/unit-tests/video/pixels/pixel_format_info_test.cpp delete mode 100644 test/unit-tests/video/pixels/pixel_format_test.cpp delete mode 100644 test/unit-tests/video/render/graphics_drivers_test.cpp delete mode 100644 test/unit-tests/video/render/renderer_handle_test.cpp delete mode 100644 test/unit-tests/video/render/renderer_test.cpp delete mode 100644 test/unit-tests/video/render/texture/scale_mode_test.cpp delete mode 100644 test/unit-tests/video/render/texture/texture_access_test.cpp delete mode 100644 test/unit-tests/video/render/texture/texture_handle_test.cpp delete mode 100644 test/unit-tests/video/render/texture/texture_test.cpp delete mode 100644 test/unit-tests/video/surface/surface_handle_test.cpp delete mode 100644 test/unit-tests/video/surface/surface_test.cpp delete mode 100644 test/unit-tests/video/window/flash_op_test.cpp delete mode 100644 test/unit-tests/video/window/window_flags_test.cpp delete mode 100644 test/unit-tests/video/window/window_handle_test.cpp delete mode 100644 test/unit-tests/video/window/window_test.cpp diff --git a/test/unit-tests/CMakeLists.txt b/test/unit-tests/CMakeLists.txt deleted file mode 100644 index 29c952972..000000000 --- a/test/unit-tests/CMakeLists.txt +++ /dev/null @@ -1,261 +0,0 @@ -cmake_minimum_required(VERSION 3.15) - -project(centurion-test-unit-tests) - -set(SOURCE_FILES - serialization_utils.hpp - - typed_test_macros.hpp - test_main.cpp - - concurrency/condition_test.cpp - concurrency/lock_status_test.cpp - concurrency/mutex_test.cpp - concurrency/scoped_lock_test.cpp - concurrency/semaphore_test.cpp - concurrency/thread_priority_test.cpp - concurrency/thread_test.cpp - concurrency/try_lock_test.cpp - - common/exception_test.cpp - common/features_test.cpp - common/log_category_test.cpp - common/log_priority_test.cpp - common/log_test.cpp - common/result_test.cpp - common/sdl_string_test.cpp - common/to_underlying_test.cpp - common/version_test.cpp - - detail/address_of_test.cpp - detail/clamp_test.cpp - detail/from_string_test.cpp - detail/max_test.cpp - detail/min_test.cpp - detail/owner_handle_api_test.cpp - - system/endian/endian_test.cpp - - event/event_base_test.cpp - event/event_dispatcher_test.cpp - event/event_handler_test.cpp - event/event_handler_type_check_test.cpp - event/event_type_test.cpp - - event/audio/audio_device_event_test.cpp - - event/controller/controller_axis_event_test.cpp - event/controller/controller_button_event_test.cpp - event/controller/controller_device_event_test.cpp - event/controller/controller_sensor_event_test.cpp - event/controller/controller_touchpad_event_test.cpp - - event/misc/display_event_id_test.cpp - event/misc/display_event_test.cpp - - event/gesture/dollar_gesture_event_test.cpp - event/gesture/multi_gesture_event_test.cpp - - event/joystick/joy_axis_event_test.cpp - event/joystick/joy_ball_event_test.cpp - event/joystick/joy_button_event_test.cpp - event/joystick/joy_device_event_test.cpp - event/joystick/joy_hat_event_test.cpp - event/joystick/joy_hat_position_test.cpp - - event/misc/drop_event_test.cpp - event/misc/keyboard_event_test.cpp - event/misc/quit_event_test.cpp - event/misc/sensor_event_test.cpp - event/misc/touch_finger_event_test.cpp - event/misc/user_event_test.cpp - - event/mouse/mouse_button_event_test.cpp - event/mouse/mouse_motion_event_test.cpp - event/mouse/mouse_wheel_direction_test.cpp - event/mouse/mouse_wheel_event_test.cpp - - event/text/text_editing_event_test.cpp - event/text/text_input_event_test.cpp - - event/window/window_event_id_test.cpp - event/window/window_event_test.cpp - - filesystem/base_path_test.cpp - filesystem/file_mode_test.cpp - filesystem/file_test.cpp - filesystem/file_type_test.cpp - filesystem/preferred_path_test.cpp - filesystem/seek_mode_test.cpp - - text/font/font_bundle_test.cpp - text/font/font_cache_test.cpp - text/font/font_hint_test.cpp - text/font/font_test.cpp - - input/button_state_test.cpp - - input/controller/controller_axis_test.cpp - input/controller/controller_bind_type_test.cpp - input/controller/controller_button_test.cpp - input/controller/controller_mapping_result_test.cpp - input/controller/controller_test.cpp - input/controller/controller_type_test.cpp - - input/joystick/hat_state_test.cpp - input/joystick/joystick_power_test.cpp - input/joystick/joystick_test.cpp - input/joystick/joystick_type_test.cpp - - input/keyboard/key_code_tests.cpp - input/keyboard/key_modifier_test.cpp - input/keyboard/keyboard_test.cpp - input/keyboard/scan_code_tests.cpp - - input/mouse/cursor_test.cpp - input/mouse/mouse_button_test.cpp - input/mouse/mouse_test.cpp - input/mouse/system_cursor_test.cpp - - input/sensor/sensor_test.cpp - input/sensor/sensor_type_test.cpp - - input/touch/touch_device_type_test.cpp - input/touch/touch_test.cpp - - common/math/area_test.cpp - common/math/rect_test.cpp - common/math/point_test.cpp - common/math/vector3_test.cpp - - common/memory/simd_block_test.cpp - - message-box/mb_button_flags_test.cpp - message-box/mb_button_order_test.cpp - message-box/mb_color_scheme.cpp - message-box/mb_color_type_test.cpp - message-box/mb_type_test.cpp - message-box/message_box_test.cpp - - video/pixels/palette_test.cpp - video/pixels/pixel_format_info_test.cpp - video/pixels/pixel_format_test.cpp - - system/power/battery_test.cpp - system/power/power_state_test.cpp - - video/render/graphics_drivers_test.cpp - video/render/renderer_handle_test.cpp - video/render/renderer_test.cpp - - video/render/texture/scale_mode_test.cpp - video/render/texture/texture_access_test.cpp - video/render/texture/texture_handle_test.cpp - video/render/texture/texture_test.cpp - - system/clipboard_test.cpp - system/counter_test.cpp - system/platform_id_test.cpp - system/platform_test.cpp - system/ram_test.cpp - system/shared_object_test.cpp - - system/locale/locale_test.cpp - - text/unicode/unicode_string_test.cpp - - video/color_test.cpp - - video/blend-mode/blend_factor_test.cpp - video/blend-mode/blend_mode_test.cpp - video/blend-mode/blend_op_test.cpp - - video/display/display_mode_test.cpp - video/display/display_test.cpp - video/display/orientation_test.cpp - - video/opengl/gl_attribute_test.cpp - video/opengl/gl_swap_interval_test.cpp - - video/surface/surface_handle_test.cpp - video/surface/surface_test.cpp - - video/window/flash_op_test.cpp - video/window/window_flags_test.cpp - video/window/window_test.cpp - video/window/window_handle_test.cpp - ) - -if (INCLUDE_AUDIO_TESTS) - list(APPEND - SOURCE_FILES - audio/fade_status_test.cpp - audio/music_test.cpp - audio/music_type_test.cpp - audio/sound_effect_test.cpp - ) -endif () - -add_executable(${CENTURION_TEST_TARGET} ${SOURCE_FILES}) - -target_include_directories(${CENTURION_TEST_TARGET} - PRIVATE - ${PROJECT_SOURCE_DIR} - ${CEN_SOURCE_DIR} - ) - -cen_include_sdl_headers(${CENTURION_TEST_TARGET}) - -cen_link_sdl_libs(${CENTURION_TEST_TARGET}) - -target_link_libraries(${CENTURION_TEST_TARGET} - PRIVATE - cereal::cereal - GLEW::GLEW - GTest::gtest - ) - -cen_set_basic_compiler_options(${CENTURION_TEST_TARGET}) - -if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - target_compile_options(${CENTURION_TEST_TARGET} - PRIVATE - /wd4834 # Disable [[nodiscard]] warnings - ) - -elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU|AppleClang") - target_compile_options(${CENTURION_TEST_TARGET} - PRIVATE - -Wno-unused-result - ) -endif () - -if (INCLUDE_AUDIO_TESTS) - target_compile_definitions(${CENTURION_TEST_TARGET} PRIVATE CENTURION_INCLUDE_AUDIO_TESTS) -endif () - -target_precompile_headers(${CENTURION_TEST_TARGET} PRIVATE - - - - - - - - - - - - - - ) - -add_test(NAME ${CENTURION_TEST_TARGET} COMMAND ${CENTURION_TEST_TARGET}) - -cen_copy_directory_post_build(${CENTURION_TEST_TARGET} - ${CEN_RESOURCES_DIR} - ${CMAKE_CURRENT_BINARY_DIR}/resources) - -if (WIN32) - cen_copy_directory_post_build(${CENTURION_TEST_TARGET} ${CEN_BINARIES_DIR} ${CMAKE_CURRENT_BINARY_DIR}) -endif () \ No newline at end of file diff --git a/test/unit-tests/audio/fade_status_test.cpp b/test/unit-tests/audio/fade_status_test.cpp deleted file mode 100644 index 188729295..000000000 --- a/test/unit-tests/audio/fade_status_test.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // cout - -#include "centurion/audio.hpp" -#include "centurion/common/utils.hpp" - -TEST(FadeStatus, Values) -{ - ASSERT_EQ(MIX_NO_FADING, to_underlying(cen::fade_status::none)); - ASSERT_EQ(MIX_FADING_IN, to_underlying(cen::fade_status::in)); - ASSERT_EQ(MIX_FADING_OUT, to_underlying(cen::fade_status::out)); -} - -TEST(FadeStatus, ToString) -{ - ASSERT_EQ("none", to_string(cen::fade_status::none)); - ASSERT_EQ("in", to_string(cen::fade_status::in)); - ASSERT_EQ("out", to_string(cen::fade_status::out)); - - std::cout << "fade_status::in == " << cen::fade_status::in << '\n'; -} diff --git a/test/unit-tests/audio/music_test.cpp b/test/unit-tests/audio/music_test.cpp deleted file mode 100644 index 57659f4dc..000000000 --- a/test/unit-tests/audio/music_test.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // clog -#include // unique_ptr -#include // ... - -#include "centurion/audio.hpp" -#include "centurion/common/logging.hpp" - -static_assert(std::is_final_v); - -static_assert(!std::is_nothrow_copy_constructible_v); -static_assert(!std::is_nothrow_copy_assignable_v); - -static_assert(std::is_nothrow_move_constructible_v); -static_assert(std::is_nothrow_move_assignable_v); - -class MusicTest : public testing::Test { - protected: - static void SetUpTestSuite() - { - mMusic = std::make_unique("resources/hidden_pond.mp3"); - } - - static void TearDownTestSuite() { mMusic.reset(); } - - inline static std::unique_ptr mMusic; -}; - -TEST_F(MusicTest, Forever) -{ - ASSERT_EQ(-1, cen::music::forever); -} - -TEST_F(MusicTest, Constructor) -{ - using namespace std::string_literals; - ASSERT_THROW(cen::music {"foobar"s}, cen::mix_error); -} - -TEST_F(MusicTest, Play) -{ - mMusic->play(); - ASSERT_TRUE(cen::music::is_playing()); - ASSERT_FALSE(cen::music::is_fading()); - ASSERT_FALSE(cen::music::is_paused()); - ASSERT_EQ(cen::fade_status::none, cen::music::get_fade_status()); - - cen::music::halt(); - - mMusic->play(cen::music::forever); - ASSERT_TRUE(cen::music::is_playing()); - ASSERT_FALSE(cen::music::is_fading()); - ASSERT_FALSE(cen::music::is_paused()); - ASSERT_EQ(cen::fade_status::none, cen::music::get_fade_status()); - - mMusic->pause(); - cen::music::halt(); -} - -TEST_F(MusicTest, Resume) -{ - ASSERT_NO_THROW(cen::music::resume()); - - mMusic->play(); - ASSERT_NO_THROW(cen::music::resume()); - - cen::music::pause(); - ASSERT_TRUE(cen::music::is_paused()); - - cen::music::resume(); - ASSERT_TRUE(cen::music::is_playing()); - - cen::music::halt(); - ASSERT_NO_THROW(cen::music::resume()); -} - -TEST_F(MusicTest, Pause) -{ - ASSERT_NO_THROW(cen::music::pause()); - - mMusic->play(); - - cen::music::pause(); - ASSERT_TRUE(cen::music::is_paused()); - - mMusic->fade_in(cen::music::ms_type {100}); - - cen::music::pause(); - ASSERT_TRUE(cen::music::is_paused()); -} - -TEST_F(MusicTest, Halt) -{ - ASSERT_NO_THROW(cen::music::halt()); - - mMusic->play(); - cen::music::halt(); - - ASSERT_FALSE(cen::music::is_playing()); - ASSERT_FALSE(cen::music::is_fading()); - - mMusic->fade_in(cen::music::ms_type {100}); - cen::music::halt(); - - ASSERT_FALSE(cen::music::is_playing()); - ASSERT_FALSE(cen::music::is_fading()); -} - -TEST_F(MusicTest, FadeIn) -{ - ASSERT_FALSE(cen::music::is_fading()); - - cen::music::halt(); - - mMusic->fade_in(cen::music::ms_type {100}); - ASSERT_TRUE(cen::music::is_fading()); - - cen::music::halt(); -} - -TEST_F(MusicTest, FadeOut) -{ - ASSERT_FALSE(cen::music::is_fading()); - - ASSERT_NO_THROW(cen::music::fade_out(cen::music::ms_type {100})); - - mMusic->fade_in(cen::music::ms_type {100}); - ASSERT_TRUE(cen::music::is_fading()); - - cen::music::halt(); -} - -TEST_F(MusicTest, SetVolume) -{ - const auto oldVolume = cen::music::volume(); - - { // Valid GetVolume - const auto volume = 102; - cen::music::set_volume(volume); - ASSERT_EQ(volume, cen::music::volume()); - } - - { // Volume underflow - const auto volume = -1; - cen::music::set_volume(volume); - ASSERT_EQ(0, cen::music::volume()); - } - - { // Volume overflow - const auto volume = cen::music::max_volume() + 1; - cen::music::set_volume(volume); - ASSERT_EQ(cen::music::max_volume(), cen::music::volume()); - } - - cen::music::set_volume(oldVolume); -} - -TEST_F(MusicTest, IsPlaying) -{ - ASSERT_FALSE(cen::music::is_playing()); - - mMusic->play(); - ASSERT_TRUE(cen::music::is_playing()); - - cen::music::halt(); - - mMusic->fade_in(cen::music::ms_type {100}); - ASSERT_TRUE(cen::music::is_playing()); - - cen::music::halt(); -} - -TEST_F(MusicTest, IsPaused) -{ - mMusic->play(); - ASSERT_FALSE(cen::music::is_paused()); - - cen::music::pause(); - ASSERT_TRUE(cen::music::is_paused()); -} - -TEST_F(MusicTest, IsFading) -{ - ASSERT_FALSE(cen::music::is_fading()); - ASSERT_FALSE(cen::music::is_fading_in()); - ASSERT_FALSE(cen::music::is_fading_out()); - - mMusic->play(); - ASSERT_FALSE(cen::music::is_fading()); - ASSERT_FALSE(cen::music::is_fading_in()); - ASSERT_FALSE(cen::music::is_fading_out()); - - cen::music::halt(); - - mMusic->fade_in(cen::music::ms_type {200}); - ASSERT_TRUE(cen::music::is_fading()); - ASSERT_TRUE(cen::music::is_fading_in()); - ASSERT_FALSE(cen::music::is_fading_out()); - - // This should have no effect, since the Music is fading in - cen::music::fade_out(cen::music::ms_type {50}); - ASSERT_TRUE(cen::music::is_fading()); - ASSERT_TRUE(cen::music::is_fading_in()); - ASSERT_FALSE(cen::music::is_fading_out()); - - cen::music::halt(); - - mMusic->play(); - cen::music::fade_out(cen::music::ms_type {50}); - ASSERT_TRUE(cen::music::is_fading()); - ASSERT_FALSE(cen::music::is_fading_in()); - ASSERT_TRUE(cen::music::is_fading_out()); - - cen::music::halt(); -} - -TEST_F(MusicTest, Volume) -{ - ASSERT_EQ(cen::music::max_volume(), cen::music::volume()); - - const auto volume = 47; - cen::music::set_volume(volume); - - ASSERT_EQ(volume, cen::music::volume()); -} - -TEST_F(MusicTest, FadeStatus) -{ - ASSERT_EQ(cen::fade_status::none, cen::music::get_fade_status()); - ASSERT_FALSE(cen::music::is_fading()); - - mMusic->fade_in(cen::music::ms_type {100}); - ASSERT_EQ(cen::fade_status::in, cen::music::get_fade_status()); - ASSERT_TRUE(cen::music::is_fading()); - ASSERT_TRUE(cen::music::is_playing()); - ASSERT_FALSE(cen::music::is_paused()); - - cen::music::halt(); - - mMusic->play(); - cen::music::fade_out(cen::music::ms_type {100}); - ASSERT_EQ(cen::fade_status::out, cen::music::get_fade_status()); - ASSERT_TRUE(cen::music::is_fading()); - ASSERT_TRUE(cen::music::is_playing()); - ASSERT_FALSE(cen::music::is_paused()); - - cen::music::halt(); - ASSERT_EQ(cen::fade_status::none, cen::music::get_fade_status()); -} - -TEST_F(MusicTest, Type) -{ - ASSERT_EQ(cen::music_type::mp3, mMusic->type()); -} - -TEST_F(MusicTest, StreamOperator) -{ - std::cout << "music == " << *mMusic << '\n'; -} \ No newline at end of file diff --git a/test/unit-tests/audio/music_type_test.cpp b/test/unit-tests/audio/music_type_test.cpp deleted file mode 100644 index 7cfe76bd8..000000000 --- a/test/unit-tests/audio/music_type_test.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // cout - -#include "centurion/audio.hpp" -#include "centurion/common/utils.hpp" - -TEST(MusicType, Values) -{ - ASSERT_EQ(MUS_NONE, to_underlying(cen::music_type::none)); - ASSERT_EQ(MUS_MP3, to_underlying(cen::music_type::mp3)); - ASSERT_EQ(MUS_WAV, to_underlying(cen::music_type::wav)); - ASSERT_EQ(MUS_CMD, to_underlying(cen::music_type::cmd)); - ASSERT_EQ(MUS_MOD, to_underlying(cen::music_type::mod)); - ASSERT_EQ(MUS_OGG, to_underlying(cen::music_type::ogg)); - ASSERT_EQ(MUS_FLAC, to_underlying(cen::music_type::flac)); - ASSERT_EQ(MUS_MID, to_underlying(cen::music_type::midi)); - ASSERT_EQ(MUS_OPUS, to_underlying(cen::music_type::opus)); -} - -TEST(MusicType, ToString) -{ - ASSERT_EQ("none", to_string(cen::music_type::none)); - ASSERT_EQ("mp3", to_string(cen::music_type::mp3)); - ASSERT_EQ("wav", to_string(cen::music_type::wav)); - ASSERT_EQ("ogg", to_string(cen::music_type::ogg)); - ASSERT_EQ("mod", to_string(cen::music_type::mod)); - ASSERT_EQ("midi", to_string(cen::music_type::midi)); - ASSERT_EQ("cmd", to_string(cen::music_type::cmd)); - ASSERT_EQ("flac", to_string(cen::music_type::flac)); - ASSERT_EQ("opus", to_string(cen::music_type::opus)); - - std::cout << "music_type::mp3 == " << cen::music_type::mp3 << '\n'; -} diff --git a/test/unit-tests/audio/sound_effect_test.cpp b/test/unit-tests/audio/sound_effect_test.cpp deleted file mode 100644 index 04041aa36..000000000 --- a/test/unit-tests/audio/sound_effect_test.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // cout -#include // unique_ptr -#include // ... - -#include "centurion/audio.hpp" - -static_assert(std::is_final_v); -static_assert(!std::is_default_constructible_v); - -static_assert(std::is_nothrow_move_constructible_v); -static_assert(std::is_nothrow_move_assignable_v); - -static_assert(!std::is_copy_constructible_v); -static_assert(!std::is_copy_assignable_v); - -inline constexpr auto path = "resources/click.wav"; - -class SoundEffect : public testing::Test { - protected: - static void SetUpTestSuite() { mSound = std::make_unique(path); } - - static void TearDownTestSuite() { mSound.reset(); } - - inline static std::unique_ptr mSound; -}; - -TEST_F(SoundEffect, Constructor) -{ - ASSERT_THROW(cen::sound_effect("foobar"), cen::mix_error); - - using namespace std::string_literals; - ASSERT_THROW(cen::sound_effect("foobar"s), cen::mix_error); -} - -TEST_F(SoundEffect, PlayAndStop) -{ - ASSERT_FALSE(mSound->is_playing()); - - mSound->play(); - ASSERT_TRUE(mSound->is_playing()); - - mSound->stop(); - ASSERT_FALSE(mSound->is_playing()); - - mSound->play(5); - ASSERT_TRUE(mSound->is_playing()); - - mSound->stop(); -} - -TEST_F(SoundEffect, Looping) -{ - const auto oldVolume = mSound->volume(); - - mSound->set_volume(1); - - mSound->play(10); - ASSERT_TRUE(mSound->is_playing()); - - mSound->stop(); - - ASSERT_LT(cen::sound_effect::forever, 0); - ASSERT_NO_THROW(mSound->play(cen::sound_effect::forever)); - - ASSERT_TRUE(mSound->is_playing()); - - mSound->stop(); - ASSERT_FALSE(mSound->is_playing()); - - mSound->set_volume(oldVolume); -} - -TEST_F(SoundEffect, FadeIn) -{ - mSound->stop(); - - ASSERT_FALSE(mSound->is_fading()); - ASSERT_FALSE(mSound->is_playing()); - - mSound->fade_in(cen::sound_effect::ms_type {100}); - ASSERT_TRUE(mSound->is_fading()); - ASSERT_TRUE(mSound->is_playing()); - - mSound->stop(); -} - -TEST_F(SoundEffect, FadeOut) -{ - ASSERT_FALSE(mSound->is_playing()); - - mSound->play(); - mSound->fade_out(cen::sound_effect::ms_type {5}); - ASSERT_TRUE(mSound->is_fading()); - ASSERT_TRUE(mSound->is_playing()); - - mSound->stop(); - ASSERT_FALSE(mSound->is_fading()); - ASSERT_FALSE(mSound->is_playing()); -} - -TEST_F(SoundEffect, SetVolume) -{ - const auto oldVolume = mSound->volume(); - - { // Valid volume - const auto volume = 27; - mSound->set_volume(volume); - ASSERT_EQ(volume, mSound->volume()); - } - - { // Volume underflow - const auto volume = -1; - mSound->set_volume(volume); - ASSERT_EQ(0, mSound->volume()); - } - - { // Volume overflow - const auto volume = cen::sound_effect::max_volume() + 1; - mSound->set_volume(volume); - ASSERT_EQ(cen::sound_effect::max_volume(), mSound->volume()); - } - - mSound->set_volume(oldVolume); -} - -TEST_F(SoundEffect, Volume) -{ - ASSERT_EQ(cen::sound_effect::max_volume(), mSound->volume()); - ASSERT_EQ(128, mSound->volume()); // because of the documentation guarantee - ASSERT_EQ(MIX_MAX_VOLUME, cen::sound_effect::max_volume()); -} - -TEST_F(SoundEffect, Forever) -{ - ASSERT_EQ(-1, cen::sound_effect::forever); -} - -TEST_F(SoundEffect, MaxVolume) -{ - ASSERT_EQ(MIX_MAX_VOLUME, cen::sound_effect::max_volume()); -} - -TEST_F(SoundEffect, StreamOperator) -{ - std::cout << "sound_effect == " << *mSound << '\n'; -} \ No newline at end of file diff --git a/test/unit-tests/common/compiler_test.cpp b/test/unit-tests/common/compiler_test.cpp deleted file mode 100644 index 771f65102..000000000 --- a/test/unit-tests/common/compiler_test.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/common/primitives.hpp" - -TEST(Compiler, IsDebugBuild) -{ -#ifdef NDEBUG - ASSERT_FALSE(cen::is_debug_build); -#else - ASSERT_TRUE(cen::is_debug_build); -#endif // NDEBUG -} - -TEST(Compiler, IsReleaseBuild) -{ -#ifdef NDEBUG - ASSERT_TRUE(cen::is_release_build); -#else - ASSERT_FALSE(cen::is_release_build); -#endif // NDEBUG -} diff --git a/test/unit-tests/common/exception_test.cpp b/test/unit-tests/common/exception_test.cpp deleted file mode 100644 index d36b408e9..000000000 --- a/test/unit-tests/common/exception_test.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include - -#include "centurion/common/errors.hpp" - -static_assert(std::has_virtual_destructor_v); -static_assert(std::is_default_constructible_v); -static_assert(std::is_nothrow_move_constructible_v); -static_assert(std::is_nothrow_destructible_v); - -TEST(Exception, NoArgsConstructor) -{ - const cen::exception exception; - ASSERT_STREQ("?", exception.what()); -} - -TEST(Exception, StringConstructor) -{ - const char* normal_msg = "Hello, world!"; - - // Limit is 128 characters, with last character reserved for null-terminator. - const char* max_msg = - ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,," // 32 - "--------------------------------" // 64 - "................................" // 96 - "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; // 127 - - const char* overflow_msg = - ",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,," // 32 - "--------------------------------" // 64 - "................................" // 96 - "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!X"; // 128 - - { - const cen::exception exception {normal_msg}; - ASSERT_STREQ(normal_msg, exception.what()); - } - - { - const cen::exception exception {max_msg}; - ASSERT_STREQ(max_msg, exception.what()); - } - - { - const cen::exception exception {overflow_msg}; - ASSERT_STREQ(max_msg, exception.what()); - } -} diff --git a/test/unit-tests/common/features_test.cpp b/test/unit-tests/common/features_test.cpp deleted file mode 100644 index d949c31dc..000000000 --- a/test/unit-tests/common/features_test.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "centurion/features.hpp" - -#include - -#include // array -#include // byte - -#if CENTURION_HAS_FEATURE_CONCEPTS -#include -#endif // CENTURION_HAS_FEATURE_CONCEPTS - -#if CENTURION_HAS_FEATURE_FORMAT -#include -#endif // CENTURION_HAS_FEATURE_FORMAT - -#if CENTURION_HAS_FEATURE_CONCEPTS - -TEST(Features, Concepts) -{ - using foo = int; - using bar = int; - static_assert(std::same_as); -} - -#endif // CENTURION_HAS_FEATURE_CONCEPTS - -#if CENTURION_HAS_FEATURE_FORMAT - -TEST(Features, Format) -{ - ASSERT_EQ("foo: 42", std::format("foo: {}", 42)); -} - -#endif // CENTURION_HAS_FEATURE_FORMAT diff --git a/test/unit-tests/common/log_category_test.cpp b/test/unit-tests/common/log_category_test.cpp deleted file mode 100644 index 5c2746ceb..000000000 --- a/test/unit-tests/common/log_category_test.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // cout - -#include "centurion/common/logging.hpp" - -TEST(LogCategory, Values) -{ - ASSERT_EQ(SDL_LOG_CATEGORY_APPLICATION, to_underlying(cen::log_category::app)); - ASSERT_EQ(SDL_LOG_CATEGORY_ERROR, to_underlying(cen::log_category::error)); - ASSERT_EQ(SDL_LOG_CATEGORY_ASSERT, to_underlying(cen::log_category::assert)); - ASSERT_EQ(SDL_LOG_CATEGORY_SYSTEM, to_underlying(cen::log_category::system)); - ASSERT_EQ(SDL_LOG_CATEGORY_AUDIO, to_underlying(cen::log_category::audio)); - ASSERT_EQ(SDL_LOG_CATEGORY_VIDEO, to_underlying(cen::log_category::video)); - ASSERT_EQ(SDL_LOG_CATEGORY_RENDER, to_underlying(cen::log_category::render)); - ASSERT_EQ(SDL_LOG_CATEGORY_INPUT, to_underlying(cen::log_category::input)); - ASSERT_EQ(SDL_LOG_CATEGORY_TEST, to_underlying(cen::log_category::test)); - ASSERT_EQ(SDL_LOG_CATEGORY_CUSTOM, to_underlying(cen::log_category::custom)); -} - -TEST(LogCategory, ToString) -{ - ASSERT_THROW(to_string(cen::log_category(SDL_LOG_CATEGORY_RESERVED1)), cen::exception); - - ASSERT_EQ("app", to_string(cen::log_category::app)); - ASSERT_EQ("error", to_string(cen::log_category::error)); - ASSERT_EQ("assert", to_string(cen::log_category::assert)); - ASSERT_EQ("system", to_string(cen::log_category::system)); - ASSERT_EQ("audio", to_string(cen::log_category::audio)); - ASSERT_EQ("video", to_string(cen::log_category::video)); - ASSERT_EQ("render", to_string(cen::log_category::render)); - ASSERT_EQ("input", to_string(cen::log_category::input)); - ASSERT_EQ("test", to_string(cen::log_category::test)); - - ASSERT_EQ("custom", to_string(cen::log_category::custom)); - ASSERT_EQ("custom", to_string(cen::log_category(SDL_LOG_CATEGORY_CUSTOM + 1))); - - std::cout << "log_category::video == " << cen::log_category::video << '\n'; -} \ No newline at end of file diff --git a/test/unit-tests/common/log_priority_test.cpp b/test/unit-tests/common/log_priority_test.cpp deleted file mode 100644 index aa199eade..000000000 --- a/test/unit-tests/common/log_priority_test.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // cout - -#include "centurion/common/logging.hpp" -#include "centurion/common/utils.hpp" - -TEST(LogPriority, Values) -{ - ASSERT_EQ(SDL_LOG_PRIORITY_INFO, to_underlying(cen::log_priority::info)); - ASSERT_EQ(SDL_LOG_PRIORITY_WARN, to_underlying(cen::log_priority::warn)); - ASSERT_EQ(SDL_LOG_PRIORITY_DEBUG, to_underlying(cen::log_priority::debug)); - ASSERT_EQ(SDL_LOG_PRIORITY_VERBOSE, to_underlying(cen::log_priority::verbose)); - ASSERT_EQ(SDL_LOG_PRIORITY_CRITICAL, to_underlying(cen::log_priority::critical)); - ASSERT_EQ(SDL_LOG_PRIORITY_ERROR, to_underlying(cen::log_priority::error)); -} - -TEST(LogPriority, ToString) -{ - ASSERT_THROW(to_string(static_cast(SDL_NUM_LOG_PRIORITIES)), - cen::exception); - - ASSERT_EQ("verbose", to_string(cen::log_priority::verbose)); - ASSERT_EQ("debug", to_string(cen::log_priority::debug)); - ASSERT_EQ("info", to_string(cen::log_priority::info)); - ASSERT_EQ("warn", to_string(cen::log_priority::warn)); - ASSERT_EQ("error", to_string(cen::log_priority::error)); - ASSERT_EQ("critical", to_string(cen::log_priority::critical)); - - std::cout << "log_priority::info == " << cen::log_priority::info << '\n'; -} diff --git a/test/unit-tests/common/log_test.cpp b/test/unit-tests/common/log_test.cpp deleted file mode 100644 index 0c3ce9d10..000000000 --- a/test/unit-tests/common/log_test.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/common/logging.hpp" - -TEST(Log, SetPriorityAllCategories) -{ - const auto priority = cen::log_priority::critical; - cen::set_priority(priority); - - ASSERT_EQ(priority, cen::get_priority(cen::log_category::app)); - ASSERT_EQ(priority, cen::get_priority(cen::log_category::error)); - ASSERT_EQ(priority, cen::get_priority(cen::log_category::assert)); - ASSERT_EQ(priority, cen::get_priority(cen::log_category::system)); - ASSERT_EQ(priority, cen::get_priority(cen::log_category::audio)); - ASSERT_EQ(priority, cen::get_priority(cen::log_category::video)); - ASSERT_EQ(priority, cen::get_priority(cen::log_category::render)); - ASSERT_EQ(priority, cen::get_priority(cen::log_category::input)); - ASSERT_EQ(priority, cen::get_priority(cen::log_category::test)); - ASSERT_EQ(priority, cen::get_priority(cen::log_category::custom)); - - cen::reset_log_priorities(); -} - -TEST(Log, SetPriority) -{ - const auto category = cen::log_category::app; - const auto priority = cen::log_priority::debug; - - cen::set_priority(category, priority); - ASSERT_EQ(priority, cen::get_priority(category)); - - cen::reset_log_priorities(); -} - -TEST(Log, GetPriority) -{ - ASSERT_EQ(SDL_LogGetPriority(SDL_LOG_CATEGORY_APPLICATION), - cen::to_underlying(cen::get_priority(cen::log_category::app))); -} - -TEST(Log, MaxMessageSize) -{ - ASSERT_EQ(SDL_MAX_LOG_MESSAGE, cen::max_log_message_size()); -} - -TEST(Log, Priority) -{ - cen::set_priority(cen::log_priority::verbose); - - cen::log_info("Info message %i", 1); - cen::log_warn("Warning message %i", 2); - cen::log_verbose("Verbose message %i", 3); - cen::log_debug("Debug message %i", 4); - cen::log_critical("Critical message %i", 5); - cen::log_error("Error message %i", 6); - - cen::reset_log_priorities(); -} - -TEST(Log, Macros) -{ - CENTURION_LOG_INFO("%s", "This is for debug only..."); - CENTURION_LOG_WARN("%s", "This is for debug only..."); - CENTURION_LOG_VERBOSE("%s", "This is for debug only..."); - CENTURION_LOG_DEBUG("%s", "This is for debug only..."); - CENTURION_LOG_CRITICAL("%s", "This is for debug only..."); - CENTURION_LOG_ERROR("%s", "This is for debug only..."); -} diff --git a/test/unit-tests/common/math/area_test.cpp b/test/unit-tests/common/math/area_test.cpp deleted file mode 100644 index 631fdb979..000000000 --- a/test/unit-tests/common/math/area_test.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // cout - -#include "centurion/common/math.hpp" -#include "serialization_utils.hpp" - -TEST(Area, DefaultConstruction) -{ - const cen::iarea area; - ASSERT_EQ(area.width, 0); - ASSERT_EQ(area.height, 0); -} - -TEST(Area, Construction) -{ - const auto width = 7353; - const auto height = 8395; - const cen::iarea area {width, height}; - - ASSERT_EQ(area.width, width); - ASSERT_EQ(area.height, height); -} - -TEST(Area, AsI) -{ - const cen::farea source {84.3f, 29.6f}; - const auto result = source.as_i(); - - ASSERT_EQ(result.width, static_cast(source.width)); - ASSERT_EQ(result.height, static_cast(source.height)); -} - -TEST(Area, AsF) -{ - const cen::iarea source {843, 203}; - const auto result = source.as_f(); - - ASSERT_EQ(result.width, static_cast(source.width)); - ASSERT_EQ(result.height, static_cast(source.height)); -} - -TEST(Area, Area) -{ - const cen::iarea iarea {123, 456}; - const cen::farea farea {12.3f, 45.6f}; - - ASSERT_EQ(123, iarea.width); - ASSERT_EQ(456, iarea.height); - - ASSERT_EQ(12.3f, farea.width); - ASSERT_EQ(45.6f, farea.height); -} - -TEST(Area, EqComparisonReflexivity) -{ - const cen::iarea area {234, 12}; - ASSERT_EQ(area, area); -} - -TEST(Area, EqComparisonSame) -{ - const cen::iarea first {47, 9123}; - const cen::iarea second {first}; - ASSERT_EQ(first, second); - ASSERT_EQ(second, first); -} - -TEST(Area, EqComparisonDifferent) -{ - const cen::iarea first {1238, 594}; - const cen::iarea second {8882, 123}; - ASSERT_NE(first, second); - ASSERT_NE(second, first); -} - -TEST(Area, NotEqComparisonSelf) -{ - const cen::iarea area {234, 12}; - ASSERT_FALSE(area != area); -} - -TEST(Area, NotEqComparisonSame) -{ - const cen::iarea first {47, 9123}; - const cen::iarea second {first}; - ASSERT_FALSE(first != second); - ASSERT_FALSE(second != first); -} - -TEST(Area, NotEqComparisonDifferent) -{ - const cen::iarea first {1238, 594}; - const cen::iarea second {8882, 123}; - ASSERT_NE(first, second); - ASSERT_NE(second, first); -} - -TEST(Area, StreamOperator) -{ - constexpr cen::iarea ia {123, 456}; - constexpr cen::farea fa {12.3f, 45.6f}; - std::cout << ia << '\n'; - std::cout << fa << '\n'; -} - -TEST(Area, Cast) -{ - { // iarea -> farea - const cen::iarea area {123, 456}; - const auto res = cen::cast(area); - ASSERT_EQ(static_cast(area.width), res.width); - ASSERT_EQ(static_cast(area.height), res.height); - } - - { // farea -> iarea - const cen::farea area {12.3f, 4.56f}; - const auto res = cen::cast(area); - ASSERT_EQ(static_cast(area.width), res.width); - ASSERT_EQ(static_cast(area.height), res.height); - } -} - -TEST(Area, AreaOf) -{ - const cen::farea area {123, 456}; - ASSERT_FLOAT_EQ(cen::area_of(area), area.width * area.height); -} - -TEST(Area, Serialization) -{ - const auto width = 123; - const auto height = 845; - serialize_save("area.binary", cen::iarea {width, height}); - - const auto other = serialize_create("area.binary"); - ASSERT_EQ(width, other.width); - ASSERT_EQ(height, other.height); -} \ No newline at end of file diff --git a/test/unit-tests/common/math/point_test.cpp b/test/unit-tests/common/math/point_test.cpp deleted file mode 100644 index 57820341c..000000000 --- a/test/unit-tests/common/math/point_test.cpp +++ /dev/null @@ -1,239 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // abs, sqrt -#include // cout -#include // ... - -#include "centurion/common/math.hpp" -#include "serialization_utils.hpp" - -static_assert(std::is_nothrow_default_constructible_v); -static_assert(std::is_nothrow_destructible_v); -static_assert(std::is_nothrow_copy_constructible_v); -static_assert(std::is_nothrow_copy_assignable_v); -static_assert(std::is_nothrow_move_constructible_v); -static_assert(std::is_nothrow_move_assignable_v); - -static_assert(std::is_nothrow_default_constructible_v); -static_assert(std::is_nothrow_destructible_v); -static_assert(std::is_nothrow_copy_constructible_v); -static_assert(std::is_nothrow_copy_assignable_v); -static_assert(std::is_nothrow_move_constructible_v); -static_assert(std::is_nothrow_move_assignable_v); - -static_assert(cen::fpoint::floating); -static_assert(!cen::ipoint::floating); - -static_assert(cen::ipoint::integral); -static_assert(!cen::fpoint::integral); - -TEST(Point, GetDistanceUnitXStep) -{ - const cen::ipoint a {0, 0}; - const cen::ipoint b {1, 0}; - - ASSERT_EQ(cen::distance(a, b), 1); - ASSERT_EQ(cen::distance(b, a), 1); -} - -TEST(Point, GetDistanceUnitYStep) -{ - const cen::ipoint a {0, 0}; - const cen::ipoint b {0, 1}; - - ASSERT_EQ(cen::distance(a, b), 1); - ASSERT_EQ(cen::distance(b, a), 1); -} - -TEST(Point, DistanceInt) -{ - const cen::ipoint a {42, 38}; - const cen::ipoint b {357, 752}; - const auto expected = 780; - - ASSERT_EQ(cen::distance(a, b), expected); - ASSERT_EQ(cen::distance(b, a), expected); -} - -TEST(Point, DistanceFloat) -{ - const cen::fpoint a {189, 86}; - const cen::fpoint b {66, 36}; - const auto expected = 17.0f * std::sqrt(61.0f); - - ASSERT_FLOAT_EQ(cen::distance(a, b), expected); - ASSERT_FLOAT_EQ(cen::distance(b, a), expected); -} - -TEST(Point, EqualityOperatorReflexivity) -{ - const cen::fpoint point; - ASSERT_EQ(point, point); -} - -TEST(Point, EqualityOperatorComparisonSame) -{ - const cen::fpoint fst {211.5f, 823.1f}; - const cen::fpoint snd {fst}; - ASSERT_EQ(fst, snd); - ASSERT_EQ(snd, fst); - ASSERT_FALSE(fst != snd); - ASSERT_FALSE(snd != fst); -} - -TEST(Point, EqualityOperatorComparisonDifferent) -{ - const cen::fpoint fst {531.5f, 8313.4f}; - const cen::fpoint snd {34.2f, 173.3f}; - ASSERT_NE(fst, snd); - ASSERT_NE(snd, fst); -} - -TEST(Point, InequalityOperatorSelf) -{ - const cen::fpoint point; - ASSERT_FALSE(point != point); -} - -TEST(Point, InequalityOperatorDifferent) -{ - const cen::fpoint fst {8392.5f, 12452.4f}; - const cen::fpoint snd {5236.2f, 321.3f}; - ASSERT_NE(fst, snd); - ASSERT_NE(snd, fst); -} - -TEST(Point, InequalityOperatorEqual) -{ - const cen::fpoint fst {211.5f, 823.1f}; - const cen::fpoint snd {fst}; - ASSERT_FALSE(fst != snd); - ASSERT_FALSE(snd != fst); -} - -TEST(Point, AdditionOperator) -{ - const cen::fpoint fst {62.4f, 381.3f}; - const cen::fpoint snd {779.3f, 819.3f}; - - const auto expectedX = fst.x() + snd.x(); - const auto expectedY = fst.y() + snd.y(); - - const auto fstSnd = fst + snd; - ASSERT_EQ(fstSnd.x(), expectedX); - ASSERT_EQ(fstSnd.y(), expectedY); - - const auto sndFst = snd + fst; - ASSERT_EQ(sndFst.x(), expectedX); - ASSERT_EQ(sndFst.y(), expectedY); -} - -TEST(Point, SubtractionOperator) -{ - const cen::fpoint fst {673, 123}; - const cen::fpoint snd {-547, 451}; - - const auto fstSnd = fst - snd; - ASSERT_EQ(fstSnd.x(), fst.x() - snd.x()); - ASSERT_EQ(fstSnd.y(), fst.y() - snd.y()); - - const auto sndFst = snd - fst; - ASSERT_EQ(sndFst.x(), snd.x() - fst.x()); - ASSERT_EQ(sndFst.y(), snd.y() - fst.y()); - - ASSERT_NE(fstSnd, sndFst); -} - -TEST(Point, IPointToFPoint) -{ - const cen::ipoint source {684, 912}; - const auto result = cen::cast(source); - - ASSERT_EQ(result.x(), static_cast(source.x())); - ASSERT_EQ(result.y(), static_cast(source.y())); -} - -TEST(Point, FPointToIPoint) -{ - const cen::fpoint source {58.8f, 123.4f}; - const auto result = cen::cast(source); - - ASSERT_EQ(result.x(), static_cast(source.x())); - ASSERT_EQ(result.y(), static_cast(source.y())); -} - -TEST(Point, AsI) -{ - const cen::fpoint source {58.8f, 123.4f}; - const auto result = source.as_i(); - - ASSERT_EQ(result.x(), static_cast(source.x())); - ASSERT_EQ(result.y(), static_cast(source.y())); -} - -TEST(Point, AsF) -{ - const cen::ipoint source {573, 9'382}; - const auto result = source.as_f(); - - ASSERT_EQ(result.x(), static_cast(source.x())); - ASSERT_EQ(result.y(), static_cast(source.y())); -} - -TEST(Point, Get) -{ - const cen::fpoint point {3923.3f, 7718.1f}; - const auto& ptr = point.get(); - - ASSERT_EQ(point.x(), ptr.x); - ASSERT_EQ(point.y(), ptr.y); -} - -TEST(Point, Data) -{ - const cen::ipoint ip {123, 456}; - ASSERT_TRUE(ip.data()); - ASSERT_EQ(123, ip.data()->x); - ASSERT_EQ(456, ip.data()->y); -} - -TEST(Point, StreamOperator) -{ - std::cout << cen::ipoint {123, 456} << '\n'; - std::cout << cen::fpoint {12.3f, 45.6f} << '\n'; -} - -TEST(Point, Serialization) -{ - const auto x = 839.9f; - const auto y = 931.5f; - serialize_save("point.binary", cen::fpoint {x, y}); - - const auto point = serialize_create("point.binary"); - ASSERT_EQ(x, point.x()); - ASSERT_EQ(y, point.y()); -} \ No newline at end of file diff --git a/test/unit-tests/common/math/rect_test.cpp b/test/unit-tests/common/math/rect_test.cpp deleted file mode 100644 index f9fb8e2fa..000000000 --- a/test/unit-tests/common/math/rect_test.cpp +++ /dev/null @@ -1,686 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // cout -#include // ... - -#include "centurion/common/math.hpp" -#include "serialization_utils.hpp" - -static_assert(std::is_nothrow_default_constructible_v); -static_assert(std::is_nothrow_default_constructible_v); - -static_assert(std::is_nothrow_copy_constructible_v); -static_assert(std::is_nothrow_copy_constructible_v); - -static_assert(std::is_nothrow_copy_assignable_v); -static_assert(std::is_nothrow_copy_assignable_v); - -static_assert(std::is_nothrow_move_constructible_v); -static_assert(std::is_nothrow_move_constructible_v); - -static_assert(std::is_nothrow_move_assignable_v); -static_assert(std::is_nothrow_move_assignable_v); - -static_assert(std::is_nothrow_destructible_v); -static_assert(std::is_nothrow_destructible_v); - -TEST(Rect, ConstexprConstruction) -{ - constexpr cen::frect rect {1, 2, 3, 4}; - static_assert(rect.x() == 1); - static_assert(rect.y() == 2); - static_assert(rect.width() == 3); - static_assert(rect.height() == 4); - static_assert(rect.has_area()); -} - -TEST(Rect, DefaultConstructor) -{ - const cen::frect rect; - ASSERT_EQ(rect.x(), 0); - ASSERT_EQ(rect.y(), 0); - ASSERT_EQ(rect.width(), 0); - ASSERT_EQ(rect.height(), 0); - ASSERT_FALSE(rect.has_area()); -} - -TEST(Rect, SDLRectConstructor) -{ - const SDL_FRect source {12.0f, 34.0f, 56.0f, 78.0f}; - const cen::frect rect {source}; - - ASSERT_EQ(source.x, rect.x()); - ASSERT_EQ(source.y, rect.y()); - ASSERT_EQ(source.w, rect.width()); - ASSERT_EQ(source.h, rect.height()); - ASSERT_TRUE(rect.has_area()); -} - -TEST(Rect, PositionAndSizeConstructor) -{ - const cen::fpoint pos {123.5f, 81.4f}; - const cen::farea size {921.8f, 512.6f}; - const cen::frect rect {pos, size}; - - ASSERT_EQ(rect.x(), pos.x()); - ASSERT_EQ(rect.y(), pos.y()); - ASSERT_EQ(rect.width(), size.width); - ASSERT_EQ(rect.height(), size.height); - - ASSERT_NO_THROW(cen::frect({{0, 0}, {0, 0}})); - ASSERT_NO_THROW(cen::frect({{0, 0}, {-1, -1}})); -} - -TEST(Rect, ValueConstructor) -{ - const auto x = 123.0f; - const auto y = 711.3f; - const auto width = 231.9f; - const auto height = 365.1f; - const cen::frect rect {x, y, width, height}; - - ASSERT_EQ(x, rect.x()); - ASSERT_EQ(y, rect.y()); - ASSERT_EQ(width, rect.width()); - ASSERT_EQ(height, rect.height()); -} - -TEST(Rect, SetX) -{ - cen::frect rect; - - const auto x = 123.4f; - rect.set_x(x); - - ASSERT_EQ(rect.x(), x); -} - -TEST(Rect, SetY) -{ - cen::frect rect; - - const auto y = 8527.1f; - rect.set_y(y); - - ASSERT_EQ(rect.y(), y); -} - -TEST(Rect, SetMaxX) -{ - cen::frect rect {{12, 92}, {241, 393}}; - - const auto mx = 74.3f; - rect.set_max_x(mx); - - ASSERT_FLOAT_EQ(mx, rect.max_x()); - ASSERT_FLOAT_EQ(241, rect.width()); -} - -TEST(Rect, SetMaxY) -{ - cen::frect rect {{12, 92}, {241, 393}}; - - const auto my = 34.3f; - rect.set_max_y(my); - - ASSERT_FLOAT_EQ(my, rect.max_y()); - ASSERT_FLOAT_EQ(393, rect.height()); -} - -TEST(Rect, SetPosition) -{ - cen::frect rect; - - const cen::fpoint pos {742.3f, 377.2f}; - rect.set_position(pos); - - ASSERT_EQ(rect.position(), pos); -} - -TEST(Rect, SetWidth) -{ - cen::frect rect; - - const auto width = 943.3f; - rect.set_width(width); - - ASSERT_EQ(rect.width(), width); -} - -TEST(Rect, SetHeight) -{ - cen::frect rect; - - const auto height = 62.35f; - rect.set_height(height); - - ASSERT_EQ(rect.height(), height); -} - -TEST(Rect, SetSize) -{ - cen::frect rect; - - const cen::farea size {345.8f, 289.7f}; - rect.set_size(size); - - ASSERT_EQ(rect.size(), size); -} - -TEST(Rect, OffsetX) -{ - const auto x = 123; - const auto y = 27; - const auto width = 100; - const auto height = 50; - - const auto offset = 84; - - cen::irect rect {x, y, width, height}; - rect.offset_x(offset); - - ASSERT_EQ(x + offset, rect.x()); - ASSERT_EQ(y, rect.y()); - ASSERT_EQ(width, rect.width()); - ASSERT_EQ(height, rect.height()); -} - -TEST(Rect, OffsetY) -{ - const auto x = 412; - const auto y = 754; - const auto width = 213; - const auto height = 886; - - const auto offset = -45; - - cen::irect rect {x, y, width, height}; - rect.offset_y(offset); - - ASSERT_EQ(x, rect.x()); - ASSERT_EQ(y + offset, rect.y()); - ASSERT_EQ(width, rect.width()); - ASSERT_EQ(height, rect.height()); -} - -TEST(Rect, OffsetWidth) -{ - const auto x = 213; - const auto y = 3125; - const auto width = 324; - const auto height = 423; - - const auto offset = 221; - - cen::irect rect {x, y, width, height}; - rect.offset_width(offset); - - ASSERT_EQ(x, rect.x()); - ASSERT_EQ(y, rect.y()); - ASSERT_EQ(width + offset, rect.width()); - ASSERT_EQ(height, rect.height()); -} - -TEST(Rect, OffsetHeight) -{ - const auto x = 34; - const auto y = 4532; - const auto width = 5431; - const auto height = 6567; - - const auto offset = 812; - - cen::irect rect {x, y, width, height}; - rect.offset_height(offset); - - ASSERT_EQ(x, rect.x()); - ASSERT_EQ(y, rect.y()); - ASSERT_EQ(width, rect.width()); - ASSERT_EQ(height + offset, rect.height()); -} - -TEST(Rect, AsI) -{ - const cen::frect source {-32.5f, 74.7f, 325.8f, 145.3f}; - const auto result = source.as_i(); - - ASSERT_EQ(result.x(), static_cast(source.x())); - ASSERT_EQ(result.y(), static_cast(source.y())); - ASSERT_EQ(result.width(), static_cast(source.width())); - ASSERT_EQ(result.height(), static_cast(source.height())); -} - -TEST(Rect, AsF) -{ - const cen::irect source {85, -32, 434, 275}; - const auto result = source.as_f(); - - ASSERT_EQ(result.x(), static_cast(source.x())); - ASSERT_EQ(result.y(), static_cast(source.y())); - ASSERT_EQ(result.width(), static_cast(source.width())); - ASSERT_EQ(result.height(), static_cast(source.height())); -} - -TEST(Rect, Contains) -{ - const cen::frect rect {{277.5f, 189.2f}, {79.2f, 58.2f}}; - - { // Top-left corner - ASSERT_TRUE(rect.contains({rect.x(), rect.y()})); - ASSERT_FALSE(rect.contains({rect.x() - 1, rect.y()})); - ASSERT_FALSE(rect.contains({rect.x(), rect.y() - 1})); - } - - { // Top-right corner - ASSERT_TRUE(rect.contains({rect.max_x(), rect.y()})); - ASSERT_FALSE(rect.contains({rect.max_x() + 1, rect.y()})); - ASSERT_FALSE(rect.contains({rect.max_x(), rect.y() - 1})); - } - - { // Bottom-left corner - ASSERT_TRUE(rect.contains({rect.x(), rect.max_y()})); - ASSERT_FALSE(rect.contains({rect.x() - 1, rect.max_y()})); - ASSERT_FALSE(rect.contains({rect.x(), rect.max_y() + 1})); - } - - { // Bottom-right corner - ASSERT_TRUE(rect.contains({rect.max_x(), rect.max_y()})); - ASSERT_FALSE(rect.contains({rect.max_x() + 1, rect.max_y()})); - ASSERT_FALSE(rect.contains({rect.max_y(), rect.max_y() + 1})); - } -} - -TEST(Rect, HasArea) -{ - { // Default constructed rectangle - const cen::frect rect; - ASSERT_FALSE(rect.has_area()); - } - - { // No width - const cen::frect rect {{0, 0}, {0, 1}}; - ASSERT_FALSE(rect.has_area()); - } - - { // No height - const cen::frect rect {{0, 0}, {1, 0}}; - ASSERT_FALSE(rect.has_area()); - } - - { // Negative dimensions - const cen::frect rect {{0, 0}, {-1, -1}}; - ASSERT_FALSE(rect.has_area()); - } - - { // Valid dimensions - const cen::frect rect {{0, 0}, {1, 1}}; - ASSERT_TRUE(rect.has_area()); - } -} - -TEST(Rect, X) -{ - const cen::frect rect; - ASSERT_EQ(rect.x(), 0); -} - -TEST(Rect, Y) -{ - const cen::frect rect; - ASSERT_EQ(rect.y(), 0); -} - -TEST(Rect, Width) -{ - const cen::frect rect; - ASSERT_EQ(rect.width(), 0); -} - -TEST(Rect, Height) -{ - const cen::frect rect; - ASSERT_EQ(rect.height(), 0); -} - -TEST(Rect, GetMaxX) -{ - const auto x = 289.2f; - const auto width = 591.0f; - - const cen::frect rect {{x, 0}, {width, 0}}; - - ASSERT_EQ(rect.max_x(), x + width); -} - -TEST(Rect, GetMaxY) -{ - const auto y = 1029.3f; - const auto height = 6961.9f; - - const cen::frect rect {{0, y}, {0, height}}; - - ASSERT_EQ(rect.max_y(), y + height); -} - -TEST(Rect, GetCenterX) -{ - const auto x = 125.3f; - const auto width = 3912.8f; - - const cen::frect rect {{x, 0}, {width, 0}}; - - ASSERT_EQ(rect.center_x(), x + (width / 2.0f)); -} - -TEST(Rect, GetCenterY) -{ - const auto y = 7128.2f; - const auto height = 1240.2f; - - const cen::frect rect {{0, y}, {0, height}}; - - ASSERT_EQ(rect.center_y(), y + (height / 2.0f)); -} - -TEST(Rect, GetArea) -{ - const auto width = 184.3f; - const auto height = 728.9f; - - const cen::frect rect {{}, {width, height}}; - - ASSERT_EQ(rect.area(), width * height); -} - -TEST(Rect, Center) -{ - const auto x = 77; - const auto y = 81; - const auto w = 128; - const auto h = 256; - - const cen::irect rect {{x, y}, {w, h}}; - const auto center = rect.center(); - - ASSERT_EQ(center.x(), x + (w / 2)); - ASSERT_EQ(center.y(), y + (h / 2)); -} - -TEST(Rect, Data) -{ - const cen::irect rect {{12, 34}, {56, 78}}; - ASSERT_TRUE(rect.data()); - ASSERT_EQ(12, rect.data()->x); - ASSERT_EQ(34, rect.data()->y); - ASSERT_EQ(56, rect.data()->w); - ASSERT_EQ(78, rect.data()->h); -} - -TEST(Rect, Intersects) -{ - const cen::frect rect {{100.0f, 100.0f}, {100.0f, 100.0f}}; - ASSERT_TRUE(cen::intersects(rect, rect)); - - { // Empty rectangle - const cen::frect empty; - ASSERT_FALSE(cen::intersects(empty, empty)); - ASSERT_FALSE(cen::intersects(rect, empty)); - ASSERT_FALSE(cen::intersects(empty, rect)); - } - - { // Obviously no intersection - const cen::frect left {{rect.x() - rect.width(), rect.y()}, {10, 10}}; - const cen::frect top {{rect.x(), rect.y() - rect.height()}, {10, 10}}; - const cen::frect right {{rect.x() + rect.width(), rect.y()}, - {rect.width(), rect.height()}}; - const cen::frect bottom {{rect.x(), rect.y() + rect.height()}, {10, 10}}; - - ASSERT_FALSE(cen::intersects(left, rect)); - ASSERT_FALSE(cen::intersects(rect, left)); - - ASSERT_FALSE(cen::intersects(top, rect)); - ASSERT_FALSE(cen::intersects(rect, top)); - - ASSERT_FALSE(cen::intersects(right, rect)); - ASSERT_FALSE(cen::intersects(rect, right)); - - ASSERT_FALSE(cen::intersects(bottom, rect)); - ASSERT_FALSE(cen::intersects(rect, bottom)); - } - - { // Edge cases - const cen::frect left {{90, 100}, {10, 10}}; - ASSERT_FALSE(cen::intersects(left, rect)); - ASSERT_FALSE(cen::intersects(rect, left)); - - const cen::frect top {{100, 90}, {10, 10}}; - ASSERT_FALSE(cen::intersects(top, rect)); - ASSERT_FALSE(cen::intersects(rect, top)); - - const cen::frect right {{200, 100}, {10, 10}}; - ASSERT_FALSE(cen::intersects(right, rect)); - ASSERT_FALSE(cen::intersects(rect, right)); - - const cen::frect bottom {{100, 200}, {10, 10}}; - ASSERT_FALSE(cen::intersects(bottom, rect)); - ASSERT_FALSE(cen::intersects(rect, bottom)); - } - - { // Obvious intersections - const cen::frect left {{90, 150}, {50, 1}}; - ASSERT_TRUE(cen::intersects(left, rect)); - ASSERT_TRUE(cen::intersects(rect, left)); - - const cen::frect top {{150, 90}, {1, 50}}; - ASSERT_TRUE(cen::intersects(top, rect)); - ASSERT_TRUE(cen::intersects(rect, top)); - - const cen::frect bottom {{150, 150}, {10, 50}}; - ASSERT_TRUE(cen::intersects(bottom, rect)); - ASSERT_TRUE(cen::intersects(rect, bottom)); - - const cen::frect right {{150, 150}, {50, 10}}; - ASSERT_TRUE(cen::intersects(right, rect)); - ASSERT_TRUE(cen::intersects(rect, right)); - } -} - -TEST(Rect, Collides) -{ - const cen::frect rect {{100.0f, 100.0f}, {100.0f, 100.0f}}; - ASSERT_TRUE(cen::overlaps(rect, rect)); - - { // Obviously no collisions - const cen::frect left {{rect.x() - rect.width() - 1, rect.y()}, {10, 10}}; - const cen::frect top {{rect.x(), rect.y() - rect.height() - 1}, {10, 10}}; - const cen::frect right {{rect.x() + rect.width() + 1, rect.y()}, - {rect.width(), rect.height()}}; - const cen::frect bottom {{rect.x(), rect.y() + rect.height() + 1}, {10, 10}}; - - ASSERT_FALSE(cen::overlaps(left, rect)); - ASSERT_FALSE(cen::overlaps(rect, left)); - - ASSERT_FALSE(cen::overlaps(top, rect)); - ASSERT_FALSE(cen::overlaps(rect, top)); - - ASSERT_FALSE(cen::overlaps(right, rect)); - ASSERT_FALSE(cen::overlaps(rect, right)); - - ASSERT_FALSE(cen::overlaps(bottom, rect)); - ASSERT_FALSE(cen::overlaps(rect, bottom)); - } - - { // Edge cases - const cen::frect left {{89, 100}, {10, 10}}; - ASSERT_FALSE(cen::overlaps(left, rect)); - ASSERT_FALSE(cen::overlaps(rect, left)); - - const cen::frect top {{100, 89}, {10, 10}}; - ASSERT_FALSE(cen::overlaps(top, rect)); - ASSERT_FALSE(cen::overlaps(rect, top)); - - const cen::frect right {{201, 100}, {10, 10}}; - ASSERT_FALSE(cen::overlaps(right, rect)); - ASSERT_FALSE(cen::overlaps(rect, right)); - - const cen::frect bottom {{100, 201}, {10, 10}}; - ASSERT_FALSE(cen::overlaps(bottom, rect)); - ASSERT_FALSE(cen::overlaps(rect, bottom)); - } - - { // Obvious collisions - const cen::frect left {{90, 150}, {50, 1}}; - ASSERT_TRUE(cen::overlaps(left, rect)); - ASSERT_TRUE(cen::overlaps(rect, left)); - - const cen::frect top {{150, 90}, {1, 50}}; - ASSERT_TRUE(cen::overlaps(top, rect)); - ASSERT_TRUE(cen::overlaps(rect, top)); - - const cen::frect bottom {{150, 150}, {10, 50}}; - ASSERT_TRUE(cen::overlaps(bottom, rect)); - ASSERT_TRUE(cen::overlaps(rect, bottom)); - - const cen::frect right {{150, 150}, {50, 10}}; - ASSERT_TRUE(cen::overlaps(right, rect)); - ASSERT_TRUE(cen::overlaps(rect, right)); - } -} - -TEST(Rect, StreamOperator) -{ - std::cout << cen::irect {12, 34, 56, 78} << '\n'; - std::cout << cen::frect {14.3f, 34.2f, 182.8f, 120.9f} << '\n'; -} - -TEST(Rect, GetUnion) -{ - const cen::frect a {{10.0f, 10.0f}, {50.0f, 50.0f}}; - const cen::frect b {{40.0f, 40.0f}, {50.0f, 50.0f}}; - - { // With empty rectangle - const cen::frect empty; - - ASSERT_EQ(cen::get_union(empty, empty), empty); - ASSERT_EQ(cen::get_union(empty, a), a); - ASSERT_EQ(cen::get_union(a, empty), a); - } - - const auto ab = cen::get_union(a, b); - const auto ba = cen::get_union(b, a); - - ASSERT_TRUE(ab.has_area()); - - ASSERT_EQ(ab.x(), 10.0f); - ASSERT_EQ(ab.y(), 10.0f); - ASSERT_EQ(ab.width(), 80.0f); - ASSERT_EQ(ab.height(), 80.0f); - - ASSERT_EQ(ab, ba); - ASSERT_EQ(ba, ab); -} - -TEST(Rect, IRectToFRect) -{ - const cen::irect source {{78, 12}, {283, 313}}; - const auto result = cen::cast(source); - - ASSERT_EQ(result.x(), static_cast(source.x())); - ASSERT_EQ(result.y(), static_cast(source.y())); - ASSERT_EQ(result.width(), static_cast(source.width())); - ASSERT_EQ(result.height(), static_cast(source.height())); -} - -TEST(Rect, FRectToIRect) -{ - const cen::frect source {{831.3f, 899.1f}, {67.2f, 91.7f}}; - const auto result = cen::cast(source); - - ASSERT_EQ(result.x(), static_cast(source.x())); - ASSERT_EQ(result.y(), static_cast(source.y())); - ASSERT_EQ(result.width(), static_cast(source.width())); - ASSERT_EQ(result.height(), static_cast(source.height())); -} - -TEST(Rect, EqualityOperatorReflexivity) -{ - const cen::frect rect {{93.3f, 67.2f}, {54.2f, 777.8f}}; - ASSERT_EQ(rect, rect); -} - -TEST(Rect, EqualityOperatorComparison) -{ - const cen::frect fst {{78.2f, 21.2f}, {9.2f, 162.3f}}; - const cen::frect snd {fst}; - ASSERT_EQ(fst, snd); - ASSERT_EQ(snd, fst); -} - -TEST(Rect, EqualityOperatorComparisonDifferent) -{ - const cen::frect fst {{8.2f, 123.3f}, {63.1f, 672.3f}}; - const cen::frect snd {{89.13f, 781.3f}, {781.2f, 331.3f}}; - ASSERT_FALSE(fst == snd); - ASSERT_FALSE(snd == fst); -} - -TEST(Rect, InequalityOperatorSelf) -{ - const cen::frect rect {{21.7f, 32.2f}, {442.2f, 383.8f}}; - ASSERT_FALSE(rect != rect); -} - -TEST(Rect, InequalityOperatorComparisonEqual) -{ - const cen::frect fst {{712.3f, 34.3f}, {65.8f, 348.2f}}; - const cen::frect snd {fst}; - ASSERT_FALSE(fst != snd); - ASSERT_FALSE(snd != fst); -} - -TEST(Rect, InequalityOperatorComparisonDifferent) -{ - const cen::frect fst {{-45.37f, 12.3f}, {89.13f, 371.3f}}; - const cen::frect snd {{738.3f, 8.24f}, {67.3f, 89.23f}}; - ASSERT_NE(fst, snd); - ASSERT_NE(snd, fst); -} - -TEST(Rect, Serialization) -{ - const auto x = 845; - const auto y = 3348; - const auto width = 412; - const auto height = 7421; - serialize_save("rect.binary", cen::irect {x, y, width, height}); - - const auto rect = serialize_create("rect.binary"); - ASSERT_EQ(x, rect.x()); - ASSERT_EQ(y, rect.y()); - ASSERT_EQ(width, rect.width()); - ASSERT_EQ(height, rect.height()); -} diff --git a/test/unit-tests/common/math/vector3_test.cpp b/test/unit-tests/common/math/vector3_test.cpp deleted file mode 100644 index 5ff6c3bc7..000000000 --- a/test/unit-tests/common/math/vector3_test.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // cout - -#include "centurion/common/math.hpp" -#include "serialization_utils.hpp" - -using float3 = cen::basic_vector3; -using int3 = cen::basic_vector3; - -TEST(Vector3, Defaults) -{ - const float3 vec; - ASSERT_EQ(0, vec.x); - ASSERT_EQ(0, vec.y); - ASSERT_EQ(0, vec.z); -} - -TEST(Vector3, CastOperator) -{ - { // int -> float - const int3 src {12, 34, 56}; - const auto result = static_cast(src); - ASSERT_EQ(static_cast(src.x), result.x); - ASSERT_EQ(static_cast(src.y), result.y); - ASSERT_EQ(static_cast(src.z), result.z); - } - - { // float -> int - const float3 src {12.3f, 45.6f, 7.89f}; - const auto result = static_cast(src); - ASSERT_EQ(static_cast(src.x), result.x); - ASSERT_EQ(static_cast(src.y), result.y); - ASSERT_EQ(static_cast(src.z), result.z); - } -} - -TEST(Vector3, StreamOperator) -{ - std::cout << float3 {12.3f, 45.6f} << '\n'; -} - -TEST(Vector3, EqualityOperator) -{ - { // Reflexivity - const float3 vec {12.3f, 45.6f}; - ASSERT_EQ(vec, vec); - } - - { // Identical vectors - const float3 vec {12.3f, 45.6f}; - const float3 copy {vec}; - ASSERT_EQ(vec, copy); - ASSERT_EQ(copy, vec); - } - - { // Different vectors - const float3 fst {27.7f, 42.6f}; - const float3 snd {954.3f, 243.2f}; - ASSERT_FALSE(fst == snd); - ASSERT_FALSE(snd == fst); - } -} - -TEST(Vector3, InequalityOperator) -{ - { // Self - const float3 vec {12.3f, 45.6f}; - ASSERT_FALSE(vec != vec); - } - - { // Identical vectors - const float3 vec {12.3f, 45.6f}; - const float3 copy {vec}; - ASSERT_FALSE(vec != copy); - ASSERT_FALSE(copy != vec); - } - - { // Different vectors - const float3 fst {27.7f, 42.6f}; - const float3 snd {954.3f, 243.2f}; - ASSERT_NE(fst, snd); - ASSERT_NE(snd, fst); - } -} - -TEST(Vector3, Serialization) -{ - const auto x = 7842; - const auto y = 3234; - const auto z = -1295; - serialize_save("basic_vector3.binary", int3 {x, y, z}); - - const auto vector = serialize_create("basic_vector3.binary"); - ASSERT_EQ(x, vector.x); - ASSERT_EQ(y, vector.y); - ASSERT_EQ(z, vector.z); -} \ No newline at end of file diff --git a/test/unit-tests/common/memory/simd_block_test.cpp b/test/unit-tests/common/memory/simd_block_test.cpp deleted file mode 100644 index eeacfff96..000000000 --- a/test/unit-tests/common/memory/simd_block_test.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/common/memory.hpp" - -TEST(SIMDBlock, Usage) -{ - cen::simd_block block {100}; - ASSERT_TRUE(block); - ASSERT_TRUE(block.data()); - - const auto& cblock = block; - ASSERT_TRUE(cblock); - ASSERT_TRUE(cblock.data()); - -#if SDL_VERSION_ATLEAST(2, 0, 14) - block.reallocate(50); - ASSERT_TRUE(block); - ASSERT_TRUE(block.data()); -#endif // SDL_VERSION_ATLEAST(2, 0, 14) -} diff --git a/test/unit-tests/common/result_test.cpp b/test/unit-tests/common/result_test.cpp deleted file mode 100644 index 41b34e238..000000000 --- a/test/unit-tests/common/result_test.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "centurion/common/result.hpp" - -#include - -#include // cout - -TEST(Result, Values) -{ - ASSERT_EQ(cen::result {true}, cen::success); - ASSERT_EQ(cen::result {false}, cen::failure); - - ASSERT_NE(cen::result {false}, cen::success); - ASSERT_NE(cen::result {true}, cen::failure); - - ASSERT_NE(cen::success, cen::failure); - - ASSERT_TRUE(cen::success); - ASSERT_FALSE(cen::failure); -} - -TEST(Result, ToString) -{ - std::cout << "result (success): '" << cen::success << "'\n"; - std::cout << "result (failure): '" << cen::failure << "'\n"; -} diff --git a/test/unit-tests/common/sdl_string_test.cpp b/test/unit-tests/common/sdl_string_test.cpp deleted file mode 100644 index 83633343f..000000000 --- a/test/unit-tests/common/sdl_string_test.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "centurion/common/sdl_string.hpp" - -#include - -TEST(SDLString, Constructor) -{ - ASSERT_NO_THROW(cen::sdl_string {nullptr}); - - const cen::sdl_string str {nullptr}; - ASSERT_FALSE(str); -} - -TEST(SDLString, Get) -{ - SDL_SetClipboardText("foo"); - const cen::sdl_string str {SDL_GetClipboardText()}; - ASSERT_STREQ(str.get(), "foo"); -} - -TEST(SDLString, Copy) -{ - { // Valid string - SDL_SetClipboardText("bar"); - const cen::sdl_string str {SDL_GetClipboardText()}; - const auto copy = str.copy(); - ASSERT_EQ("bar", copy); - } - - { // Empty string - SDL_SetClipboardText(nullptr); - const cen::sdl_string empty {SDL_GetClipboardText()}; - ASSERT_TRUE(empty.copy().empty()); - } - - { // Null string - const cen::sdl_string str {nullptr}; - ASSERT_EQ("", str.copy()); - } -} diff --git a/test/unit-tests/common/to_underlying_test.cpp b/test/unit-tests/common/to_underlying_test.cpp deleted file mode 100644 index 4d3b00e59..000000000 --- a/test/unit-tests/common/to_underlying_test.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/common/primitives.hpp" -#include "centurion/common/utils.hpp" - -using foo_type = cen::ulonglong; -using bar_type = char; - -enum class foo : foo_type { - a = 27, - b = 42, - c = 123 -}; - -enum class bar : bar_type { - a = 'a', - b = '1', - c = 'x' -}; - -static_assert(std::is_same_v); -static_assert(std::is_same_v); - -TEST(to_underlying, to_underlying) -{ - ASSERT_EQ(27u, cen::to_underlying(foo::a)); - ASSERT_EQ(42u, cen::to_underlying(foo::b)); - ASSERT_EQ(123u, cen::to_underlying(foo::c)); - - ASSERT_EQ('a', cen::to_underlying(bar::a)); - ASSERT_EQ('1', cen::to_underlying(bar::b)); - ASSERT_EQ('x', cen::to_underlying(bar::c)); -} diff --git a/test/unit-tests/common/version_test.cpp b/test/unit-tests/common/version_test.cpp deleted file mode 100644 index fc801fa2d..000000000 --- a/test/unit-tests/common/version_test.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "centurion/common/version.hpp" - -#include - -TEST(Version, CurrentVersion) -{ - ASSERT_EQ(7, CENTURION_VERSION_MAJOR); - ASSERT_EQ(3, CENTURION_VERSION_MINOR); - ASSERT_EQ(0, CENTURION_VERSION_PATCH); - - const auto version = cen::current_version(); - ASSERT_EQ(7, version.major); - ASSERT_EQ(3, version.minor); - ASSERT_EQ(0, version.patch); -} - -TEST(Version, VersionAtLeast) -{ - ASSERT_FALSE(cen::version_at_least(CENTURION_VERSION_MAJOR, CENTURION_VERSION_MINOR + 1, 0)); - ASSERT_FALSE(cen::version_at_least(CENTURION_VERSION_MAJOR, - CENTURION_VERSION_MINOR, - CENTURION_VERSION_PATCH + 1)); - - ASSERT_TRUE(cen::version_at_least(CENTURION_VERSION_MAJOR, - CENTURION_VERSION_MINOR, - CENTURION_VERSION_PATCH)); - ASSERT_TRUE(cen::version_at_least(7, 2, 0)); - ASSERT_TRUE(cen::version_at_least(7, 1, 0)); - ASSERT_TRUE(cen::version_at_least(7, 0, 0)); - ASSERT_TRUE(cen::version_at_least(6, 3, 1)); - ASSERT_TRUE(cen::version_at_least(6, 3, 0)); - ASSERT_TRUE(cen::version_at_least(6, 2, 0)); - ASSERT_TRUE(cen::version_at_least(6, 1, 0)); - ASSERT_TRUE(cen::version_at_least(6, 0, 1)); - ASSERT_TRUE(cen::version_at_least(6, 0, 0)); - ASSERT_TRUE(cen::version_at_least(5, 3, 0)); - ASSERT_TRUE(cen::version_at_least(5, 2, 0)); - ASSERT_TRUE(cen::version_at_least(5, 1, 0)); - ASSERT_TRUE(cen::version_at_least(5, 0, 0)); - ASSERT_TRUE(cen::version_at_least(4, 0, 0)); -} - -TEST(Version, Defaults) -{ - const cen::version version; - ASSERT_EQ(0, version.major); - ASSERT_EQ(0, version.minor); - ASSERT_EQ(0, version.patch); -} - -TEST(Version, SDLLinkedVersion) -{ - SDL_version expected {}; - SDL_GetVersion(&expected); - - const auto version = cen::sdl_linked_version(); - ASSERT_EQ(expected.major, version.major); - ASSERT_EQ(expected.minor, version.minor); - ASSERT_EQ(expected.patch, version.patch); -} - -TEST(Version, SDLImageLinkedVersion) -{ - const auto expected = *IMG_Linked_Version(); - const auto version = cen::sdl_image_linked_version(); - ASSERT_EQ(expected.major, version.major); - ASSERT_EQ(expected.minor, version.minor); - ASSERT_EQ(expected.patch, version.patch); -} - -TEST(Version, SDLMixerLinkedVersion) -{ - const auto expected = *Mix_Linked_Version(); - const auto version = cen::sdl_mixer_linked_version(); - ASSERT_EQ(expected.major, version.major); - ASSERT_EQ(expected.minor, version.minor); - ASSERT_EQ(expected.patch, version.patch); -} - -TEST(Version, SDLTTFLinkedVersion) -{ - const auto expected = *TTF_Linked_Version(); - const auto version = cen::sdl_ttf_linked_version(); - ASSERT_EQ(expected.major, version.major); - ASSERT_EQ(expected.minor, version.minor); - ASSERT_EQ(expected.patch, version.patch); -} - -TEST(Version, SDLVersion) -{ - const auto version = cen::sdl_version(); - ASSERT_EQ(SDL_MAJOR_VERSION, version.major); - ASSERT_EQ(SDL_MINOR_VERSION, version.minor); - ASSERT_EQ(SDL_PATCHLEVEL, version.patch); -} - -TEST(Version, SDLImageVersion) -{ - const auto version = cen::sdl_image_version(); - ASSERT_EQ(SDL_IMAGE_MAJOR_VERSION, version.major); - ASSERT_EQ(SDL_IMAGE_MINOR_VERSION, version.minor); - ASSERT_EQ(SDL_IMAGE_PATCHLEVEL, version.patch); -} - -TEST(Version, SDLMixerVersion) -{ - const auto version = cen::sdl_mixer_version(); - ASSERT_EQ(SDL_MIXER_MAJOR_VERSION, version.major); - ASSERT_EQ(SDL_MIXER_MINOR_VERSION, version.minor); - ASSERT_EQ(SDL_MIXER_PATCHLEVEL, version.patch); -} - -TEST(Version, SDLTTFVersion) -{ - const auto version = cen::sdl_ttf_version(); - ASSERT_EQ(SDL_TTF_MAJOR_VERSION, version.major); - ASSERT_EQ(SDL_TTF_MINOR_VERSION, version.minor); - ASSERT_EQ(SDL_TTF_PATCHLEVEL, version.patch); -} diff --git a/test/unit-tests/concurrency/condition_test.cpp b/test/unit-tests/concurrency/condition_test.cpp deleted file mode 100644 index ada7bd17b..000000000 --- a/test/unit-tests/concurrency/condition_test.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "centurion/concurrency/condition.hpp" - -#include - -#include "centurion/common/literals.hpp" -#include "centurion/concurrency/thread.hpp" - -TEST(Condition, Signal) -{ - cen::condition cond; - ASSERT_TRUE(cond.signal()); -} - -TEST(Condition, Broadcast) -{ - cen::condition cond; - ASSERT_TRUE(cond.broadcast()); -} - -TEST(Condition, Wait) -{ - cen::mutex mutex; - cen::condition cond; - - ASSERT_TRUE(mutex.lock()); - - cen::thread thread {[](void* data) { - auto* cond = reinterpret_cast(data); - - using namespace cen::literals::time_literals; - cen::thread::sleep(50_ms); - - cond->signal(); - - return 0; - }, - "thread", - &cond}; - - ASSERT_TRUE(cond.wait(mutex)); - ASSERT_TRUE(mutex.unlock()); -} diff --git a/test/unit-tests/concurrency/lock_status_test.cpp b/test/unit-tests/concurrency/lock_status_test.cpp deleted file mode 100644 index 3183209a4..000000000 --- a/test/unit-tests/concurrency/lock_status_test.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // cout - -#include "centurion/concurrency/locks.hpp" - -TEST(LockStatus, Values) -{ - ASSERT_EQ(0, to_underlying(cen::lock_status::success)); - ASSERT_EQ(SDL_MUTEX_TIMEDOUT, to_underlying(cen::lock_status::timed_out)); - ASSERT_EQ(-1, to_underlying(cen::lock_status::error)); -} - -TEST(LockStatus, to_string) -{ - ASSERT_THROW(to_string(static_cast(2)), cen::exception); - - ASSERT_EQ("success", to_string(cen::lock_status::success)); - ASSERT_EQ("timed_out", to_string(cen::lock_status::timed_out)); - ASSERT_EQ("error", to_string(cen::lock_status::error)); - - std::cout << "lock_status::timed_out == " << cen::lock_status::timed_out << '\n'; -} diff --git a/test/unit-tests/concurrency/mutex_test.cpp b/test/unit-tests/concurrency/mutex_test.cpp deleted file mode 100644 index 43d461760..000000000 --- a/test/unit-tests/concurrency/mutex_test.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "centurion/concurrency/mutex.hpp" - -#include - -TEST(Mutex, LockAndUnlock) -{ - cen::mutex mutex; - - ASSERT_TRUE(mutex.lock()); - ASSERT_TRUE(mutex.unlock()); -} - -TEST(Mutex, TryLock) -{ - cen::mutex mutex; - - ASSERT_EQ(mutex.try_lock(), cen::lock_status::success); - ASSERT_TRUE(mutex.unlock()); -} - -TEST(Mutex, Data) -{ - cen::mutex mutex; - ASSERT_TRUE(mutex.data()); - - const auto& ref = mutex; - ASSERT_TRUE(ref.data()); -} diff --git a/test/unit-tests/concurrency/scoped_lock_test.cpp b/test/unit-tests/concurrency/scoped_lock_test.cpp deleted file mode 100644 index df4cf588e..000000000 --- a/test/unit-tests/concurrency/scoped_lock_test.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include - -#include "centurion/concurrency/locks.hpp" - -static_assert(!std::is_copy_constructible_v); -static_assert(!std::is_copy_assignable_v); - -TEST(ScopedLock, Construction) -{ - cen::mutex mutex; - ASSERT_NO_THROW(cen::scoped_lock {mutex}); -} diff --git a/test/unit-tests/concurrency/semaphore_test.cpp b/test/unit-tests/concurrency/semaphore_test.cpp deleted file mode 100644 index d51e4a901..000000000 --- a/test/unit-tests/concurrency/semaphore_test.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "centurion/concurrency/semaphore.hpp" - -#include - -#include "centurion/common/literals.hpp" - -TEST(Semaphore, Acquire) -{ - cen::semaphore semaphore {1}; - - ASSERT_TRUE(semaphore.acquire()); - ASSERT_EQ(semaphore.count(), 0u); - - ASSERT_TRUE(semaphore.release()); - ASSERT_EQ(semaphore.count(), 1u); -} - -TEST(Semaphore, AcquireMilliseconds) -{ - using namespace cen::literals::time_literals; - - cen::semaphore semaphore {0u}; - - ASSERT_EQ(semaphore.acquire(1_ms), cen::lock_status::timed_out); - ASSERT_TRUE(semaphore.release()); - - ASSERT_EQ(semaphore.acquire(1_ms), cen::lock_status::success); -} - -TEST(Semaphore, TryAcquire) -{ - cen::semaphore semaphore {0u}; - - ASSERT_EQ(semaphore.try_acquire(), cen::lock_status::timed_out); - ASSERT_TRUE(semaphore.release()); - - ASSERT_EQ(semaphore.try_acquire(), cen::lock_status::success); -} - -TEST(Semaphore, Release) -{ - cen::semaphore semaphore {0u}; - ASSERT_EQ(semaphore.count(), 0u); - - ASSERT_TRUE(semaphore.release()); - ASSERT_EQ(semaphore.count(), 1u); -} - -TEST(Semaphore, Count) -{ - constexpr Uint32 tokens = 32; - - cen::semaphore semaphore {tokens}; - ASSERT_EQ(semaphore.count(), tokens); -} diff --git a/test/unit-tests/concurrency/thread_priority_test.cpp b/test/unit-tests/concurrency/thread_priority_test.cpp deleted file mode 100644 index 92464b5e2..000000000 --- a/test/unit-tests/concurrency/thread_priority_test.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // cout - -#include "centurion/concurrency/thread.hpp" - -TEST(ThreadPriority, Values) -{ - ASSERT_EQ(SDL_THREAD_PRIORITY_LOW, to_underlying(cen::thread_priority::low)); - ASSERT_EQ(SDL_THREAD_PRIORITY_NORMAL, to_underlying(cen::thread_priority::normal)); - ASSERT_EQ(SDL_THREAD_PRIORITY_HIGH, to_underlying(cen::thread_priority::high)); - ASSERT_EQ(SDL_THREAD_PRIORITY_TIME_CRITICAL, to_underlying(cen::thread_priority::critical)); -} - -TEST(ThreadPriority, to_string) -{ - ASSERT_THROW(to_string(static_cast(5)), cen::exception); - - ASSERT_EQ("low", to_string(cen::thread_priority::low)); - ASSERT_EQ("normal", to_string(cen::thread_priority::normal)); - ASSERT_EQ("high", to_string(cen::thread_priority::high)); - ASSERT_EQ("critical", to_string(cen::thread_priority::critical)); - - std::cout << "thread_priority::high == " << cen::thread_priority::high << '\n'; -} diff --git a/test/unit-tests/concurrency/thread_test.cpp b/test/unit-tests/concurrency/thread_test.cpp deleted file mode 100644 index 584c7eafc..000000000 --- a/test/unit-tests/concurrency/thread_test.cpp +++ /dev/null @@ -1,186 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "centurion/concurrency/thread.hpp" - -#include - -#include -#include - -#include "centurion/common/literals.hpp" -#include "centurion/common/logging.hpp" - -namespace { - -auto dummy = [](void*) noexcept -> int { - using namespace cen::literals; - cen::thread::sleep(2_ms); - return 0; -}; - -} // namespace - -static_assert(std::is_same_v); - -static_assert(!std::is_copy_constructible_v); -static_assert(!std::is_copy_assignable_v); - -TEST(Thread, Detach) -{ - cen::thread thread {dummy}; - thread.detach(); - - ASSERT_FALSE(thread.joinable()); - ASSERT_FALSE(thread.joined()); - ASSERT_TRUE(thread.detached()); - - ASSERT_NO_THROW(thread.detach()); -} - -TEST(Thread, Join) -{ - cen::thread thread {dummy}; - thread.join(); - - ASSERT_FALSE(thread.joinable()); - ASSERT_TRUE(thread.joined()); - ASSERT_FALSE(thread.detached()); - - ASSERT_EQ(thread.join(), 0); -} - -TEST(Thread, Joinable) -{ - { // Shouldn't be joinable after join - cen::thread thread {dummy}; - ASSERT_TRUE(thread.joinable()); - - thread.join(); - ASSERT_FALSE(thread.joinable()); - } - - { // Shouldn't be joinable after detach - cen::thread thread {dummy}; - ASSERT_TRUE(thread.joinable()); - - thread.detach(); - ASSERT_FALSE(thread.joinable()); - } -} - -TEST(Thread, Joined) -{ - cen::thread thread {dummy}; - ASSERT_FALSE(thread.joined()); - - thread.join(); - ASSERT_TRUE(thread.joined()); -} - -TEST(Thread, Detached) -{ - cen::thread thread {dummy}; - ASSERT_FALSE(thread.detached()); - - thread.detach(); - ASSERT_TRUE(thread.detached()); -} - -TEST(Thread, ID) -{ - cen::thread thread {dummy}; - ASSERT_EQ(thread.id(), SDL_GetThreadID(thread.data())); -} - -TEST(Thread, Name) -{ - { // Custom name - const cen::thread thread {dummy, "foobar"}; - ASSERT_EQ(thread.name(), "foobar"); - } - - { // Default name - const cen::thread thread {dummy}; - ASSERT_EQ(thread.name(), "thread"); - } -} - -TEST(Thread, Data) -{ - cen::thread thread {dummy}; - ASSERT_TRUE(thread.data()); - - const auto& ref = thread; - ASSERT_TRUE(ref.data()); -} - -TEST(Thread, Sleep) -{ - using namespace cen::literals::time_literals; - ASSERT_NO_THROW(cen::thread::sleep(2_ms)); - ASSERT_NO_THROW(cen::thread::sleep(0_ms)); -} - -TEST(Thread, SetPriority) -{ - ASSERT_TRUE(cen::thread::set_priority(cen::thread_priority::low)); -} - -TEST(Thread, CurrentId) -{ - ASSERT_EQ(cen::thread::current_id(), SDL_ThreadID()); -} - -TEST(Thread, StreamOperator) -{ - cen::thread thread {dummy, "cen-thread"}; - std::cout << thread << '\n'; -} - -#if CENTURION_HAS_FEATURE_CONCEPTS - -TEST(Thread, Init) -{ - { // No arguments - auto thread = cen::thread::init([] {}); - ASSERT_TRUE(thread.joinable()); - ASSERT_EQ(0, thread.join()); - } - - { // No arguments but returns integer - auto thread = cen::thread::init([] { return 42; }); - ASSERT_TRUE(thread.joinable()); - ASSERT_EQ(42, thread.join()); - } - - { // With user data - int i = 123; - auto thread = cen::thread::init([](int* data) { return *data; }, &i); - ASSERT_TRUE(thread.joinable()); - ASSERT_EQ(123, thread.join()); - } -} - -#endif // CENTURION_HAS_FEATURE_CONCEPTS diff --git a/test/unit-tests/concurrency/try_lock_test.cpp b/test/unit-tests/concurrency/try_lock_test.cpp deleted file mode 100644 index a530be4ba..000000000 --- a/test/unit-tests/concurrency/try_lock_test.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include - -#include "centurion/concurrency/locks.hpp" - -static_assert(!std::is_copy_constructible_v); -static_assert(!std::is_copy_assignable_v); - -TEST(TryLock, BasicUsage) -{ - cen::mutex mutex; - cen::try_lock lock {mutex}; - - ASSERT_TRUE(lock.locked()); -} - -TEST(TryLock, GetStatus) -{ - cen::mutex mutex; - cen::try_lock lock {mutex}; - - ASSERT_EQ(cen::lock_status::success, lock.status()); - - ASSERT_TRUE(lock.locked()); - ASSERT_FALSE(lock.timed_out()); - ASSERT_FALSE(lock.failed()); -} - -TEST(TryLock, BoolConversion) -{ - cen::mutex mutex; - cen::try_lock lock {mutex}; - - ASSERT_TRUE(lock); -} diff --git a/test/unit-tests/detail/address_of_test.cpp b/test/unit-tests/detail/address_of_test.cpp deleted file mode 100644 index 1931f136a..000000000 --- a/test/unit-tests/detail/address_of_test.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // clog - -#include "centurion/detail/stdlib.hpp" - -TEST(AddressOf, Correctness) -{ - { // Non-null pointer - int i = 42; - const auto str = cen::detail::address_of(&i); - - ASSERT_FALSE(str.empty()); - -#if CENTURION_HAS_FEATURE_CPP20 - ASSERT_TRUE(str.starts_with("0x")); -#endif // CENTURION_HAS_FEATURE_CPP20 - - std::cout << "detail::address_of output: " << str << '\n'; - } - - { // Null pointer - int* i {}; - ASSERT_NO_THROW(cen::detail::address_of(i)); - - const auto str = cen::detail::address_of(i); - ASSERT_TRUE(str.empty()); - } -} diff --git a/test/unit-tests/detail/clamp_test.cpp b/test/unit-tests/detail/clamp_test.cpp deleted file mode 100644 index e9961c5d8..000000000 --- a/test/unit-tests/detail/clamp_test.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/detail/stdlib.hpp" - -TEST(Clamp, Correctness) -{ - ASSERT_EQ(1, cen::detail::clamp(1, 0, 1)); - ASSERT_EQ(1, cen::detail::clamp(1, 1, 1)); - ASSERT_EQ(1, cen::detail::clamp(1, 0, 2)); - ASSERT_EQ(1, cen::detail::clamp(1, -1, 2)); - - ASSERT_EQ(2, cen::detail::clamp(3, 0, 2)); - ASSERT_EQ(0, cen::detail::clamp(-1, 0, 2)); - - ASSERT_EQ(-2, cen::detail::clamp(-2, -3, -1)); - ASSERT_EQ(-3, cen::detail::clamp(-4, -3, -1)); - ASSERT_EQ(-1, cen::detail::clamp(0, -3, -1)); -} diff --git a/test/unit-tests/detail/from_string_test.cpp b/test/unit-tests/detail/from_string_test.cpp deleted file mode 100644 index 3d5d04e80..000000000 --- a/test/unit-tests/detail/from_string_test.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/detail/stdlib.hpp" - -TEST(FromString, IntegerBase10) -{ - ASSERT_FALSE(cen::detail::stoi("foo")); - - ASSERT_EQ(42, cen::detail::stoi("42")); - ASSERT_EQ(123, cen::detail::stoi("123")); - ASSERT_EQ(-834, cen::detail::stoi("-834")); -} - -TEST(FromString, IntegerBase16) -{ - ASSERT_FALSE(cen::detail::stoi("foo", 16)); - - ASSERT_EQ(0xB7, cen::detail::stoi("B7", 16)); - ASSERT_EQ(0x123, cen::detail::stoi("123", 16)); - ASSERT_EQ(0xE9A, cen::detail::stoi("E9A", 16)); -} diff --git a/test/unit-tests/detail/max_test.cpp b/test/unit-tests/detail/max_test.cpp deleted file mode 100644 index 3fe83ae22..000000000 --- a/test/unit-tests/detail/max_test.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/detail/stdlib.hpp" - -TEST(Max, Correctness) -{ - ASSERT_EQ(0, cen::detail::max(0, -1)); - ASSERT_EQ(1, cen::detail::max(0, 1)); - - ASSERT_EQ(1, cen::detail::max(1, -1)); - ASSERT_EQ(1, cen::detail::max(-1, 1)); - - ASSERT_EQ(2, cen::detail::max(1, 2)); - ASSERT_EQ(2, cen::detail::max(2, 1)); - - ASSERT_EQ(-1, cen::detail::max(-1, -2)); - ASSERT_EQ(-1, cen::detail::max(-2, -1)); -} diff --git a/test/unit-tests/detail/min_test.cpp b/test/unit-tests/detail/min_test.cpp deleted file mode 100644 index 8c343e666..000000000 --- a/test/unit-tests/detail/min_test.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/detail/stdlib.hpp" - -TEST(Min, Correctness) -{ - ASSERT_EQ(-1, cen::detail::min(0, -1)); - ASSERT_EQ(0, cen::detail::min(0, 1)); - - ASSERT_EQ(-1, cen::detail::min(1, -1)); - ASSERT_EQ(-1, cen::detail::min(-1, 1)); - - ASSERT_EQ(1, cen::detail::min(1, 2)); - ASSERT_EQ(1, cen::detail::min(2, 1)); - - ASSERT_EQ(-2, cen::detail::min(-1, -2)); - ASSERT_EQ(-2, cen::detail::min(-2, -1)); -} diff --git a/test/unit-tests/detail/owner_handle_api_test.cpp b/test/unit-tests/detail/owner_handle_api_test.cpp deleted file mode 100644 index f9cd0157e..000000000 --- a/test/unit-tests/detail/owner_handle_api_test.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "centurion/detail/owner_handle_api.hpp" - -#include - -#include "centurion/common/memory.hpp" - -inline int delete_count = 0; - -namespace cen { - -template <> -struct deleter final { - void operator()(const int* ptr) noexcept - { - ++delete_count; - delete ptr; - } -}; - -} // namespace cen - -using Owner = cen::detail::pointer; -using Handle = cen::detail::pointer; - -static_assert(std::is_nothrow_default_constructible_v); -static_assert(std::is_nothrow_default_constructible_v); - -static_assert(!std::is_copy_constructible_v); -static_assert(std::is_nothrow_copy_constructible_v); - -static_assert(std::is_nothrow_move_constructible_v); -static_assert(std::is_nothrow_move_constructible_v); - -static_assert(noexcept(Owner {nullptr})); -static_assert(noexcept(Handle {nullptr})); - -TEST(OwnerHandleAPI, Constructor) -{ - ASSERT_NO_THROW(Owner {nullptr}); - ASSERT_NO_THROW(Handle {nullptr}); - - { - int i = 42; - - Handle handle {&i}; - const auto& cHandle = handle; - - ASSERT_TRUE(handle); - ASSERT_TRUE(cHandle); - ASSERT_TRUE(handle.get()); - ASSERT_TRUE(cHandle.get()); - ASSERT_TRUE(handle.operator->()); - ASSERT_TRUE(cHandle.operator->()); - ASSERT_NO_FATAL_FAILURE(handle.operator*()); - ASSERT_NO_FATAL_FAILURE(cHandle.operator*()); - } - - { - Handle handle {nullptr}; - const auto& cHandle = handle; - - ASSERT_FALSE(handle); - ASSERT_FALSE(cHandle); - ASSERT_FALSE(handle.get()); - ASSERT_FALSE(cHandle.get()); - ASSERT_FALSE(handle.operator->()); - ASSERT_FALSE(cHandle.operator->()); - } -} - -TEST(OwnerHandleAPI, DeleteCorrectness) -{ - Owner {new int {7}}; - - int i = 7; - Handle {&i}; - - ASSERT_EQ(1, delete_count); -} - -TEST(OwnerHandleAPI, Get) -{ - int i = 7; - Handle handle {&i}; - ASSERT_EQ(&i, handle.get()); -} diff --git a/test/unit-tests/event/audio/audio_device_event_test.cpp b/test/unit-tests/event/audio/audio_device_event_test.cpp deleted file mode 100644 index b3a06cfdb..000000000 --- a/test/unit-tests/event/audio/audio_device_event_test.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/audio_events.hpp" - -TEST(AudioDeviceEvent, Defaults) -{ - const cen::audio_device_event event; - ASSERT_EQ(cen::event_type::audio_device_added, event.type()); -} - -TEST(AudioDeviceEvent, SetWhich) -{ - cen::audio_device_event event; - - const Uint32 which = 7; - event.set_which(which); - - ASSERT_EQ(which, event.which()); -} - -TEST(AudioDeviceEvent, SetCapture) -{ - cen::audio_device_event event; - - event.set_capture(true); - ASSERT_TRUE(event.is_capture()); - ASSERT_FALSE(event.is_output()); - - event.set_capture(false); - ASSERT_FALSE(event.is_capture()); - ASSERT_TRUE(event.is_output()); -} - -TEST(AudioDeviceEvent, AsSDLEvent) -{ - const cen::audio_device_event event; - const auto underlying = cen::as_sdl_event(event); - - ASSERT_EQ(underlying.adevice.type, cen::to_underlying(event.type())); - ASSERT_EQ(underlying.adevice.timestamp, event.timestamp().count()); -} diff --git a/test/unit-tests/event/controller/controller_axis_event_test.cpp b/test/unit-tests/event/controller/controller_axis_event_test.cpp deleted file mode 100644 index 5e35fb6f7..000000000 --- a/test/unit-tests/event/controller/controller_axis_event_test.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/controller_events.hpp" - -TEST(ControllerAxisEvent, Defaults) -{ - const cen::controller_axis_event event; - ASSERT_EQ(cen::event_type::controller_axis_motion, event.type()); -} - -TEST(ControllerAxisEvent, SetWhich) -{ - cen::controller_axis_event event; - - const SDL_JoystickID id = 53; - event.set_which(id); - - ASSERT_EQ(id, event.which()); -} - -TEST(ControllerAxisEvent, SetAxis) -{ - cen::controller_axis_event event; - - const auto axis = cen::controller_axis::trigger_right; - event.set_axis(axis); - - ASSERT_EQ(axis, event.axis()); -} - -TEST(ControllerAxisEvent, SetValue) -{ - cen::controller_axis_event event; - - const cen::int16 value = 4576; - event.set_value(value); - - ASSERT_EQ(value, event.value()); -} - -TEST(ControllerAxisEvent, AsSDLEvent) -{ - const cen::controller_axis_event event; - const auto underlying = cen::as_sdl_event(event); - - ASSERT_EQ(underlying.caxis.type, cen::to_underlying(event.type())); - ASSERT_EQ(underlying.caxis.timestamp, event.timestamp().count()); -} \ No newline at end of file diff --git a/test/unit-tests/event/controller/controller_button_event_test.cpp b/test/unit-tests/event/controller/controller_button_event_test.cpp deleted file mode 100644 index b9cedd334..000000000 --- a/test/unit-tests/event/controller/controller_button_event_test.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/controller_events.hpp" - -TEST(ControllerButtonEvent, Defaults) -{ - const cen::controller_button_event event; - ASSERT_EQ(cen::event_type::controller_button_down, event.type()); -} - -TEST(ControllerButtonEvent, SetButton) -{ - cen::controller_button_event event; - - event.set_button(cen::controller_button::a); - ASSERT_EQ(cen::controller_button::a, event.button()); -} - -TEST(ControllerButtonEvent, SetState) -{ - cen::controller_button_event event; - - event.set_state(cen::button_state::pressed); - - ASSERT_EQ(cen::button_state::pressed, event.state()); - ASSERT_TRUE(event.is_pressed()); - ASSERT_FALSE(event.is_released()); - - event.set_state(cen::button_state::released); - - ASSERT_EQ(cen::button_state::released, event.state()); - ASSERT_TRUE(event.is_released()); - ASSERT_FALSE(event.is_pressed()); -} - -TEST(ControllerButtonEvent, SetWhich) -{ - cen::controller_button_event event; - - const SDL_JoystickID id = 7; - event.set_which(id); - - ASSERT_EQ(id, event.which()); -} - -TEST(ControllerButtonEvent, AsSDLEvent) -{ - const cen::controller_button_event event; - const auto underlying = cen::as_sdl_event(event); - - ASSERT_EQ(underlying.cbutton.type, cen::to_underlying(event.type())); - ASSERT_EQ(underlying.cbutton.timestamp, event.timestamp().count()); -} \ No newline at end of file diff --git a/test/unit-tests/event/controller/controller_device_event_test.cpp b/test/unit-tests/event/controller/controller_device_event_test.cpp deleted file mode 100644 index 63f52593d..000000000 --- a/test/unit-tests/event/controller/controller_device_event_test.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/controller_events.hpp" - -TEST(ControllerDeviceEvent, Defaults) -{ - const cen::controller_device_event event; - ASSERT_EQ(cen::event_type::controller_device_added, event.type()); -} - -TEST(ControllerDeviceEvent, SetWhich) -{ - cen::controller_device_event event; - - const cen::int32 which = 4; - event.set_which(which); - - ASSERT_EQ(which, event.which()); -} - -TEST(ControllerDeviceEvent, AsSDLEvent) -{ - const cen::controller_device_event event; - const auto underlying = cen::as_sdl_event(event); - - ASSERT_EQ(underlying.cdevice.type, cen::to_underlying(event.type())); - ASSERT_EQ(underlying.cdevice.timestamp, event.timestamp().count()); -} diff --git a/test/unit-tests/event/controller/controller_sensor_event_test.cpp b/test/unit-tests/event/controller/controller_sensor_event_test.cpp deleted file mode 100644 index 0331a99a0..000000000 --- a/test/unit-tests/event/controller/controller_sensor_event_test.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // array - -#include "centurion/common/literals.hpp" -#include "centurion/events/controller_events.hpp" - -#if SDL_VERSION_ATLEAST(2, 0, 14) - -TEST(ControllerSensorEvent, Defaults) -{ - const cen::controller_sensor_event event; - ASSERT_EQ(0, event.which()); - ASSERT_EQ(cen::sensor_type::unknown, event.sensor()); -} - -TEST(ControllerSensorEvent, SetWhich) -{ - cen::controller_sensor_event event; - - const SDL_JoystickID id = 38; - event.set_which(id); - - ASSERT_EQ(id, event.which()); -} - -TEST(ControllerSensorEvent, SetSensor) -{ - cen::controller_sensor_event event; - - event.set_sensor(cen::sensor_type::accelerometer); - ASSERT_EQ(cen::sensor_type::accelerometer, event.sensor()); -} - -TEST(ControllerSensorEvent, SetData) -{ - cen::controller_sensor_event event; - - const std::array values = {0.3f, 0.5f, 0.8f}; - - event.set_data(values); - ASSERT_EQ(0.3f, event.data().at(0)); - ASSERT_EQ(0.5f, event.data().at(1)); - ASSERT_EQ(0.8f, event.data().at(2)); -} - -TEST(ControllerSensorEvent, AsSdlEvent) -{ - using namespace cen::literals::time_literals; - - cen::controller_sensor_event event; - event.set_timestamp(4'895_ms); - event.set_sensor(cen::sensor_type::gyroscope); - event.set_which(21); - - const auto sdl = cen::as_sdl_event(event); - ASSERT_EQ(4'895u, sdl.csensor.timestamp); - ASSERT_EQ(SDL_CONTROLLERSENSORUPDATE, static_cast(sdl.csensor.type)); - ASSERT_EQ(SDL_SENSOR_GYRO, static_cast(sdl.csensor.sensor)); - ASSERT_EQ(21, sdl.csensor.which); -} - -#endif // SDL_VERSION_ATLEAST(2, 0, 14) diff --git a/test/unit-tests/event/controller/controller_touchpad_event_test.cpp b/test/unit-tests/event/controller/controller_touchpad_event_test.cpp deleted file mode 100644 index 27f2e7a47..000000000 --- a/test/unit-tests/event/controller/controller_touchpad_event_test.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/controller_events.hpp" - -#if SDL_VERSION_ATLEAST(2, 0, 14) - -TEST(ControllerTouchpadEvent, Defaults) -{ - const cen::controller_touchpad_event event; - ASSERT_EQ(0, event.which()); - ASSERT_EQ(0, event.finger_index()); - ASSERT_EQ(0, event.x()); - ASSERT_EQ(0, event.y()); - ASSERT_EQ(0, event.pressure()); -} - -TEST(ControllerTouchpadEvent, SetWhich) -{ - cen::controller_touchpad_event event; - - const SDL_JoystickID id = 832; - event.set_which(id); - - ASSERT_EQ(id, event.which()); -} - -TEST(ControllerTouchpadEvent, SetTouchpadIndex) -{ - cen::controller_touchpad_event event; - - const cen::int32 index = 32; - event.set_touchpad_index(index); - - ASSERT_EQ(index, event.touchpad_index()); -} - -TEST(ControllerTouchpadEvent, SetFingerIndex) -{ - cen::controller_touchpad_event event; - - const cen::int32 index = 27; - event.set_finger_index(index); - - ASSERT_EQ(index, event.finger_index()); -} - -TEST(ControllerTouchpadEvent, SetX) -{ - cen::controller_touchpad_event event; - - event.set_x(0.4f); - ASSERT_EQ(0.4f, event.x()); - - event.set_x(-0.5f); - ASSERT_EQ(0, event.x()); - - event.set_x(1.2f); - ASSERT_EQ(1.0f, event.x()); -} - -TEST(ControllerTouchpadEvent, SetY) -{ - cen::controller_touchpad_event event; - - event.set_y(0.8f); - ASSERT_EQ(0.8f, event.y()); - - event.set_y(-0.1f); - ASSERT_EQ(0, event.y()); - - event.set_y(4.2f); - ASSERT_EQ(1.0f, event.y()); -} - -TEST(ControllerTouchpadEvent, SetPressure) -{ - cen::controller_touchpad_event event; - - event.set_pressure(0.1f); - ASSERT_EQ(0.1f, event.pressure()); - - event.set_pressure(-1.4f); - ASSERT_EQ(0, event.pressure()); - - event.set_pressure(5.3f); - ASSERT_EQ(1.0f, event.pressure()); -} - -#endif // SDL_VERSION_ATLEAST(2, 0, 14) diff --git a/test/unit-tests/event/event_base_test.cpp b/test/unit-tests/event/event_base_test.cpp deleted file mode 100644 index 1c6e9a520..000000000 --- a/test/unit-tests/event/event_base_test.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "centurion/events/event_base.hpp" - -#include - -#include "centurion/common/literals.hpp" -#include "centurion/events/misc_events.hpp" - -using sdl_event = SDL_QuitEvent; // A simple SDL event type for testing -using common_event = cen::quit_event; - -using namespace cen::literals::time_literals; - -TEST(EventBase, SetTimestamp) -{ - common_event event; - - const auto time = 8'934_ms; - event.set_timestamp(time); - - ASSERT_EQ(time, event.timestamp()); -} - -TEST(EventBase, SetType) -{ - common_event event; - - const auto type = cen::event_type::app_low_memory; - event.set_type(type); - - ASSERT_EQ(type, event.type()); -} - -TEST(EventBase, Timestamp) -{ - const auto time = 8'321_ms; - - sdl_event sdl; - sdl.timestamp = static_cast(time.count()); - - const common_event event {sdl}; - ASSERT_EQ(time, event.timestamp()); -} - -TEST(EventBase, Type) -{ - sdl_event sdl; - sdl.type = SDL_MOUSEMOTION; - - const common_event event {sdl}; - ASSERT_EQ(cen::event_type::mouse_motion, event.type()); -} - -TEST(EventBase, Get) -{ - sdl_event sdl; - sdl.type = SDL_MOUSEMOTION; - - const common_event event {sdl}; - const auto& internal = event.get(); - - ASSERT_EQ(sdl.type, internal.type); -} diff --git a/test/unit-tests/event/event_dispatcher_test.cpp b/test/unit-tests/event/event_dispatcher_test.cpp deleted file mode 100644 index f764195ad..000000000 --- a/test/unit-tests/event/event_dispatcher_test.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "centurion/events/event_dispatcher.hpp" - -#include - -#include // cout - -using EventDispatcher = - cen::event_dispatcher; - -namespace { - -inline bool gVisitedFreeFunction {}; - -void OnQuit(const cen::quit_event&) -{ - gVisitedFreeFunction = true; -} - -struct ButtonHandler final { - void OnEvent(const cen::controller_button_event&) { visited = true; } - - bool visited {}; -}; - -} // namespace - -TEST(EventDispatcher, Bind) -{ - /* Ensure that it is possible to connect free functions, member functions, and - lambdas as event handlers. */ - - cen::event_handler::flush_all(); - - ButtonHandler handler; - EventDispatcher dispatcher; - - dispatcher.bind().to<&OnQuit>(); - dispatcher.bind().to<&ButtonHandler::OnEvent>(&handler); - - bool visitedLambda {}; - dispatcher.bind().to( - [&](const cen::window_event&) { visitedLambda = true; }); - - cen::window_event windowEvent; - ASSERT_TRUE(cen::event_handler::push(windowEvent)); - - cen::quit_event quitEvent; - ASSERT_TRUE(cen::event_handler::push(quitEvent)); - - cen::controller_button_event buttonEvent; - ASSERT_TRUE(cen::event_handler::push(buttonEvent)); - - dispatcher.poll(); - ASSERT_TRUE(handler.visited); - ASSERT_TRUE(gVisitedFreeFunction); - ASSERT_TRUE(visitedLambda); -} - -TEST(EventDispatcher, Reset) -{ - EventDispatcher dispatcher; - ASSERT_EQ(0, dispatcher.active_count()); - - dispatcher.bind().to([](cen::quit_event) {}); - dispatcher.bind().to([](cen::window_event) {}); - dispatcher.bind().to([](cen::controller_button_event) {}); - - ASSERT_EQ(3, dispatcher.active_count()); - - dispatcher.reset(); - ASSERT_EQ(0, dispatcher.active_count()); - - ASSERT_NO_THROW(dispatcher.reset()); -} - -TEST(EventDispatcher, ActiveCount) -{ - EventDispatcher dispatcher; - ASSERT_EQ(0, dispatcher.active_count()); - - dispatcher.bind().to([](cen::quit_event) {}); - ASSERT_EQ(1, dispatcher.active_count()); - - // Bind same event to another lambda, should replace the previous handler - dispatcher.bind().to([](cen::quit_event) {}); - ASSERT_EQ(1, dispatcher.active_count()); - - dispatcher.bind().to([](cen::window_event) {}); - ASSERT_EQ(2, dispatcher.active_count()); -} - -TEST(EventDispatcher, Size) -{ - cen::event_dispatcher zero; - ASSERT_EQ(0, zero.size()); - - cen::event_dispatcher one; - ASSERT_EQ(1, one.size()); - - cen::event_dispatcher two; - ASSERT_EQ(2, two.size()); -} - -TEST(EventDispatcher, StreamOperator) -{ - EventDispatcher dispatcher; - std::cout << dispatcher << '\n'; -} diff --git a/test/unit-tests/event/event_handler_test.cpp b/test/unit-tests/event/event_handler_test.cpp deleted file mode 100644 index 9a0128231..000000000 --- a/test/unit-tests/event/event_handler_test.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include - -#include "centurion/events/event_handler.hpp" - -namespace { - -template -[[nodiscard]] constexpr auto validate() noexcept -> bool -{ - return !std::has_virtual_destructor_v && std::is_nothrow_copy_constructible_v && - std::is_nothrow_copy_assignable_v && std::is_nothrow_move_constructible_v && - std::is_nothrow_move_assignable_v && std::is_nothrow_constructible_v && - std::is_final_v; -} - -} // namespace - -static_assert(validate()); - -static_assert(validate()); -static_assert(validate()); -static_assert(validate()); - -static_assert(validate()); -static_assert(validate()); - -static_assert(validate()); - -static_assert(validate()); -static_assert(validate()); -static_assert(validate()); -static_assert(validate()); -static_assert(validate()); - -static_assert(validate()); -static_assert(validate()); -static_assert(validate()); -static_assert(validate()); -static_assert(validate()); - -static_assert(validate()); -static_assert(validate()); - -static_assert(validate()); -static_assert(validate()); -static_assert(validate()); - -static_assert(validate()); - -#if SDL_VERSION_ATLEAST(2, 0, 14) -static_assert(validate()); -static_assert(validate()); -static_assert(validate()); -#endif // SDL_VERSION_ATLEAST(2, 0, 14) - -TEST(Event, Push) -{ - cen::event_handler::flush_all(); - - cen::keyboard_event event; - event.set_type(cen::event_type::key_up); - ASSERT_TRUE(cen::event_handler::push(event)); - - cen::event_handler handler; - ASSERT_TRUE(handler.poll()); - ASSERT_EQ(cen::event_type::key_up, handler.type()); -} - -TEST(Event, Flush) -{ - cen::event_handler::update(); - cen::event_handler::flush(); - - cen::event_handler event; - ASSERT_FALSE(event.poll()); -} - -TEST(Event, FlushAll) -{ - cen::event_handler::flush_all(); - - cen::event_handler event; - ASSERT_FALSE(event.poll()); -} - -TEST(Event, Poll) -{ - SDL_Event sdl {}; - sdl.type = SDL_MOUSEMOTION; - sdl.motion.x = 839; - sdl.motion.y = 351; - - cen::event_handler::flush(); - SDL_PushEvent(&sdl); - - cen::event_handler event; - ASSERT_TRUE(event.poll()); - - ASSERT_EQ(cen::event_type::mouse_motion, event.type()); - ASSERT_TRUE(event.is()); - - auto& motionEvent = event.get(); - ASSERT_EQ(sdl.motion.x, motionEvent.x()); - ASSERT_EQ(sdl.motion.y, motionEvent.y()); - - cen::event_handler::flush_all(); -} - -TEST(Event, QueueCount) -{ - cen::event_handler::flush_all(); - ASSERT_EQ(0, cen::event_handler::queue_count()); - ASSERT_EQ(0, cen::event_handler::queue_count(cen::event_type::quit)); - - cen::quit_event event; - cen::event_handler::push(event); - - ASSERT_EQ(1, cen::event_handler::queue_count()); - ASSERT_EQ(1, cen::event_handler::queue_count(cen::event_type::quit)); - ASSERT_EQ(0, cen::event_handler::queue_count(cen::event_type::window)); -} - -TEST(Event, InQueue) -{ - cen::event_handler::flush_all(); - ASSERT_FALSE(cen::event_handler::in_queue(cen::event_type::quit)); - - cen::quit_event qe; - cen::event_handler::push(qe); - - ASSERT_TRUE(cen::event_handler::in_queue(cen::event_type::quit)); - ASSERT_FALSE(cen::event_handler::in_queue(cen::event_type::window)); - - cen::event_handler::flush_all(); - ASSERT_FALSE(cen::event_handler::in_queue(cen::event_type::quit)); -} - -TEST(Event, Type) -{ - SDL_Event sdl {}; - sdl.type = SDL_FINGERMOTION; - - cen::event_handler::flush_all(); - SDL_PushEvent(&sdl); - - cen::event_handler event; - ASSERT_TRUE(event.poll()); - ASSERT_EQ(cen::event_type::finger_motion, event.type()); - - cen::event_handler::flush_all(); -} - -TEST(Event, Get) -{ - cen::event_handler::flush_all(); - - cen::quit_event event; - cen::event_handler::push(event); - - cen::event_handler handler; - ASSERT_TRUE(handler.poll()); - - ASSERT_NO_THROW(handler.get()); - ASSERT_ANY_THROW(handler.get()); - - const auto& ref = handler; - ASSERT_NO_THROW(ref.get()); - ASSERT_ANY_THROW(ref.get()); -} - -TEST(Event, TryGet) -{ - cen::event_handler::flush_all(); - - cen::mouse_motion_event event; - cen::event_handler::push(event); - - cen::event_handler handler; - ASSERT_TRUE(handler.poll()); - - ASSERT_TRUE(handler.try_get()); - ASSERT_FALSE(handler.try_get()); - - const auto& ref = handler; - ASSERT_TRUE(ref.try_get()); - ASSERT_FALSE(ref.try_get()); -} diff --git a/test/unit-tests/event/event_handler_type_check_test.cpp b/test/unit-tests/event/event_handler_type_check_test.cpp deleted file mode 100644 index 3d60fc60b..000000000 --- a/test/unit-tests/event/event_handler_type_check_test.cpp +++ /dev/null @@ -1,216 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/event_handler.hpp" - -namespace { - -template -void check(const SDL_EventType type) -{ - SDL_Event event {}; - event.type = type; - - cen::event_handler::flush_all(); - SDL_PushEvent(&event); - - cen::event_handler handler; - ASSERT_TRUE(handler.poll()); - - const auto strong = static_cast(type); - - ASSERT_EQ(static_cast(type), handler.raw_type()); - ASSERT_EQ(strong, handler.type()); - - ASSERT_TRUE(handler.is(strong)); - ASSERT_TRUE(handler.is()); -} - -} // namespace - -#if SDL_VERSION_ATLEAST(2, 0, 14) - -TEST(EventHandlerTypeChecks, DisplayEvent) -{ - check(SDL_DISPLAYEVENT); -} - -#endif // SDL_VERSION_ATLEAST(2, 0, 14) - -TEST(EventHandlerTypeChecks, WindowEvent) -{ - check(SDL_WINDOWEVENT); -} - -TEST(EventHandlerTypeChecks, KeyboardEvent) -{ - check(SDL_KEYDOWN); - check(SDL_KEYUP); -} - -TEST(EventHandlerTypeChecks, TextEditingEvent) -{ - check(SDL_TEXTEDITING); -} - -TEST(EventHandlerTypeChecks, TextInputEvent) -{ - check(SDL_TEXTINPUT); -} - -TEST(EventHandlerTypeChecks, MouseMotionEvent) -{ - check(SDL_MOUSEMOTION); -} - -TEST(EventHandlerTypeChecks, MouseButtonEvent) -{ - check(SDL_MOUSEBUTTONDOWN); - check(SDL_MOUSEBUTTONUP); -} - -TEST(EventHandlerTypeChecks, MouseWheelEvent) -{ - check(SDL_MOUSEWHEEL); -} - -TEST(EventHandlerTypeChecks, JoyAxisEvent) -{ - check(SDL_JOYAXISMOTION); -} - -TEST(EventHandlerTypeChecks, JoyBallEvent) -{ - check(SDL_JOYBALLMOTION); -} - -TEST(EventHandlerTypeChecks, JoyHatEvent) -{ - check(SDL_JOYHATMOTION); -} - -TEST(EventHandlerTypeChecks, JoyButtonEvent) -{ - check(SDL_JOYBUTTONDOWN); - check(SDL_JOYBUTTONUP); -} - -TEST(EventHandlerTypeChecks, DISABLED_JoyDeviceEvent) -{ - check(SDL_JOYDEVICEADDED); - check(SDL_JOYDEVICEREMOVED); -} - -TEST(EventHandlerTypeChecks, ControllerAxisEvent) -{ - check(SDL_CONTROLLERAXISMOTION); -} - -TEST(EventHandlerTypeChecks, ControllerButtonEvent) -{ - check(SDL_CONTROLLERBUTTONDOWN); - check(SDL_CONTROLLERBUTTONUP); -} - -TEST(EventHandlerTypeChecks, ControllerDeviceEvent) -{ - check(SDL_CONTROLLERDEVICEADDED); - check(SDL_CONTROLLERDEVICEREMAPPED); - check(SDL_CONTROLLERDEVICEREMOVED); -} - -#if SDL_VERSION_ATLEAST(2, 0, 14) - -TEST(EventHandlerTypeChecks, ControllerTouchpadEvent) -{ - check(SDL_CONTROLLERTOUCHPADDOWN); - check(SDL_CONTROLLERTOUCHPADMOTION); - check(SDL_CONTROLLERTOUCHPADUP); -} - -TEST(EventHandlerTypeChecks, ControllerSensorEvent) -{ - check(SDL_CONTROLLERSENSORUPDATE); -} - -#endif // SDL_VERSION_ATLEAST(2, 0, 14) - -TEST(EventHandlerTypeChecks, AudioDeviceEvent) -{ - check(SDL_AUDIODEVICEADDED); - check(SDL_AUDIODEVICEREMOVED); -} - -TEST(EventHandlerTypeChecks, TouchFingerEvent) -{ - check(SDL_FINGERMOTION); - check(SDL_FINGERDOWN); - check(SDL_FINGERUP); -} - -TEST(EventHandlerTypeChecks, MultiGestureEvent) -{ - check(SDL_MULTIGESTURE); -} - -TEST(EventHandlerTypeChecks, DollarGestureEvent) -{ - check(SDL_DOLLARGESTURE); - check(SDL_DOLLARRECORD); -} - -TEST(EventHandlerTypeChecks, DropEvent) -{ - check(SDL_DROPBEGIN); - check(SDL_DROPFILE); - check(SDL_DROPTEXT); - check(SDL_DROPCOMPLETE); -} - -TEST(EventHandlerTypeChecks, SensorEvent) -{ - check(SDL_SENSORUPDATE); -} - -TEST(EventHandlerTypeChecks, QuitEvent) -{ - check(SDL_QUIT); -} - -TEST(EventHandlerTypeChecks, UserEvent) -{ - check(SDL_USEREVENT); - check(static_cast(SDL_USEREVENT + 1)); - check(static_cast(SDL_USEREVENT + 2)); - check(static_cast(SDL_USEREVENT + 42)); - check(static_cast(SDL_LASTEVENT - 2)); - check(static_cast(SDL_LASTEVENT - 1)); -} - -TEST(EventHandlerTypeChecks, SysWMEvent) -{ - // TODO check(SDL_SYSWMEVENT); -} \ No newline at end of file diff --git a/test/unit-tests/event/event_type_test.cpp b/test/unit-tests/event/event_type_test.cpp deleted file mode 100644 index 603ec77b9..000000000 --- a/test/unit-tests/event/event_type_test.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // cout - -#include "centurion/events/event_base.hpp" - -using type = cen::event_type; - -TEST(EventType, Values) -{ - ASSERT_EQ(SDL_FIRSTEVENT, to_underlying(type::first_event)); - ASSERT_EQ(SDL_LASTEVENT, to_underlying(type::last_event)); - -#if SDL_VERSION_ATLEAST(2, 0, 18) - ASSERT_EQ(SDL_POLLSENTINEL, to_underlying(type::poll_sentinel)); -#endif // SDL_VERSION_ATLEAST(2, 0, 18) - - ASSERT_EQ(SDL_QUIT, to_underlying(type::quit)); - - ASSERT_EQ(SDL_APP_TERMINATING, to_underlying(type::app_terminating)); - ASSERT_EQ(SDL_APP_LOWMEMORY, to_underlying(type::app_low_memory)); - ASSERT_EQ(SDL_APP_WILLENTERBACKGROUND, to_underlying(type::app_will_enter_background)); - ASSERT_EQ(SDL_APP_DIDENTERBACKGROUND, to_underlying(type::app_did_enter_background)); - ASSERT_EQ(SDL_APP_DIDENTERFOREGROUND, to_underlying(type::app_did_enter_foreground)); - -#if SDL_VERSION_ATLEAST(2, 0, 14) - ASSERT_EQ(SDL_DISPLAYEVENT, to_underlying(type::display)); -#endif // SDL_VERSION_ATLEAST(2, 0, 14) - ASSERT_EQ(SDL_WINDOWEVENT, to_underlying(type::window)); - ASSERT_EQ(SDL_SYSWMEVENT, to_underlying(type::system)); - - ASSERT_EQ(SDL_KEYDOWN, to_underlying(type::key_down)); - ASSERT_EQ(SDL_KEYUP, to_underlying(type::key_up)); - ASSERT_EQ(SDL_TEXTEDITING, to_underlying(type::text_editing)); -#if SDL_VERSION_ATLEAST(2, 0, 22) - ASSERT_EQ(SDL_TEXTEDITING_EXT, to_underlying(type::text_editing_ext)); -#endif // SDL_VERSION_ATLEAST(2, 0, 22) - ASSERT_EQ(SDL_TEXTINPUT, to_underlying(type::text_input)); - ASSERT_EQ(SDL_KEYMAPCHANGED, to_underlying(type::keymap_changed)); - - ASSERT_EQ(SDL_MOUSEMOTION, to_underlying(type::mouse_motion)); - ASSERT_EQ(SDL_MOUSEBUTTONDOWN, to_underlying(type::mouse_button_down)); - ASSERT_EQ(SDL_MOUSEBUTTONUP, to_underlying(type::mouse_button_up)); - ASSERT_EQ(SDL_MOUSEWHEEL, to_underlying(type::mouse_wheel)); - - ASSERT_EQ(SDL_JOYAXISMOTION, to_underlying(type::joy_axis_motion)); - ASSERT_EQ(SDL_JOYBALLMOTION, to_underlying(type::joy_ball_motion)); - ASSERT_EQ(SDL_JOYHATMOTION, to_underlying(type::joy_hat_motion)); - ASSERT_EQ(SDL_JOYBUTTONDOWN, to_underlying(type::joy_button_down)); - ASSERT_EQ(SDL_JOYBUTTONUP, to_underlying(type::joy_button_up)); - ASSERT_EQ(SDL_JOYDEVICEADDED, to_underlying(type::joy_device_added)); - ASSERT_EQ(SDL_JOYDEVICEREMOVED, to_underlying(type::joy_device_removed)); -#if SDL_VERSION_ATLEAST(2, 24, 0) - ASSERT_EQ(SDL_JOYBATTERYUPDATED, to_underlying(type::joy_battery_updated)); -#endif // SDL_VERSION_ATLEAST(2, 24, 0) - - ASSERT_EQ(SDL_CONTROLLERAXISMOTION, to_underlying(type::controller_axis_motion)); - ASSERT_EQ(SDL_CONTROLLERBUTTONDOWN, to_underlying(type::controller_button_down)); - ASSERT_EQ(SDL_CONTROLLERBUTTONUP, to_underlying(type::controller_button_up)); - ASSERT_EQ(SDL_CONTROLLERDEVICEADDED, to_underlying(type::controller_device_added)); - ASSERT_EQ(SDL_CONTROLLERDEVICEREMOVED, to_underlying(type::controller_device_removed)); - ASSERT_EQ(SDL_CONTROLLERDEVICEREMAPPED, to_underlying(type::controller_device_remapped)); - - ASSERT_EQ(SDL_FINGERDOWN, to_underlying(type::finger_down)); - ASSERT_EQ(SDL_FINGERUP, to_underlying(type::finger_up)); - ASSERT_EQ(SDL_FINGERMOTION, to_underlying(type::finger_motion)); - - ASSERT_EQ(SDL_DOLLARGESTURE, to_underlying(type::dollar_gesture)); - ASSERT_EQ(SDL_DOLLARRECORD, to_underlying(type::dollar_record)); - ASSERT_EQ(SDL_MULTIGESTURE, to_underlying(type::multi_gesture)); - - ASSERT_EQ(SDL_CLIPBOARDUPDATE, to_underlying(type::clipboard_update)); - - ASSERT_EQ(SDL_DROPFILE, to_underlying(type::drop_file)); - ASSERT_EQ(SDL_DROPTEXT, to_underlying(type::drop_text)); - ASSERT_EQ(SDL_DROPBEGIN, to_underlying(type::drop_begin)); - ASSERT_EQ(SDL_DROPCOMPLETE, to_underlying(type::drop_complete)); - - ASSERT_EQ(SDL_AUDIODEVICEADDED, to_underlying(type::audio_device_added)); - ASSERT_EQ(SDL_AUDIODEVICEREMOVED, to_underlying(type::audio_device_removed)); - - ASSERT_EQ(SDL_SENSORUPDATE, to_underlying(type::sensor_update)); - - ASSERT_EQ(SDL_RENDER_TARGETS_RESET, to_underlying(type::render_targets_reset)); - ASSERT_EQ(SDL_RENDER_DEVICE_RESET, to_underlying(type::render_device_reset)); - - ASSERT_EQ(SDL_USEREVENT, to_underlying(type::user)); - -#if SDL_VERSION_ATLEAST(2, 0, 14) - ASSERT_EQ(SDL_LOCALECHANGED, to_underlying(type::locale_changed)); - - ASSERT_EQ(SDL_CONTROLLERTOUCHPADDOWN, to_underlying(type::controller_touchpad_down)); - ASSERT_EQ(SDL_CONTROLLERTOUCHPADUP, to_underlying(type::controller_touchpad_up)); - ASSERT_EQ(SDL_CONTROLLERTOUCHPADMOTION, to_underlying(type::controller_touchpad_motion)); - ASSERT_EQ(SDL_CONTROLLERSENSORUPDATE, to_underlying(type::controller_sensor_update)); -#endif // SDL_VERSION_ATLEAST(2, 0, 14) -} - -TEST(EventType, ToString) -{ - ASSERT_EQ("first_event", to_string(type::first_event)); - ASSERT_EQ("last_event", to_string(type::last_event)); -#if SDL_VERSION_ATLEAST(2, 0, 18) - ASSERT_EQ("poll_sentinel", to_string(type::poll_sentinel)); -#endif // SDL_VERSION_ATLEAST(2, 0, 18) - - ASSERT_EQ("quit", to_string(type::quit)); - - ASSERT_EQ("app_terminating", to_string(type::app_terminating)); - ASSERT_EQ("app_low_memory", to_string(type::app_low_memory)); - ASSERT_EQ("app_will_enter_background", to_string(type::app_will_enter_background)); - ASSERT_EQ("app_did_enter_background", to_string(type::app_did_enter_background)); - ASSERT_EQ("app_did_enter_foreground", to_string(type::app_did_enter_foreground)); - -#if SDL_VERSION_ATLEAST(2, 0, 14) - ASSERT_EQ("display", to_string(type::display)); -#endif // SDL_VERSION_ATLEAST(2, 0, 14) - ASSERT_EQ("window", to_string(type::window)); - ASSERT_EQ("system", to_string(type::system)); - - ASSERT_EQ("key_down", to_string(type::key_down)); - ASSERT_EQ("key_up", to_string(type::key_up)); - ASSERT_EQ("text_editing", to_string(type::text_editing)); -#if SDL_VERSION_ATLEAST(2, 0, 22) - ASSERT_EQ("text_editing_ext", to_string(type::text_editing_ext)); -#endif // SDL_VERSION_ATLEAST(2, 0, 22) - ASSERT_EQ("text_input", to_string(type::text_input)); - ASSERT_EQ("keymap_changed", to_string(type::keymap_changed)); - - ASSERT_EQ("mouse_motion", to_string(type::mouse_motion)); - ASSERT_EQ("mouse_button_down", to_string(type::mouse_button_down)); - ASSERT_EQ("mouse_button_up", to_string(type::mouse_button_up)); - ASSERT_EQ("mouse_wheel", to_string(type::mouse_wheel)); - - ASSERT_EQ("joy_axis_motion", to_string(type::joy_axis_motion)); - ASSERT_EQ("joy_ball_motion", to_string(type::joy_ball_motion)); - ASSERT_EQ("joy_hat_motion", to_string(type::joy_hat_motion)); - ASSERT_EQ("joy_button_down", to_string(type::joy_button_down)); - ASSERT_EQ("joy_button_up", to_string(type::joy_button_up)); - ASSERT_EQ("joy_device_added", to_string(type::joy_device_added)); - ASSERT_EQ("joy_device_removed", to_string(type::joy_device_removed)); -#if SDL_VERSION_ATLEAST(2, 24, 0) - ASSERT_EQ("joy_battery_updated", to_string(type::joy_battery_updated)); -#endif // SDL_VERSION_ATLEAST(2, 24, 0) - - ASSERT_EQ("controller_axis_motion", to_string(type::controller_axis_motion)); - ASSERT_EQ("controller_button_down", to_string(type::controller_button_down)); - ASSERT_EQ("controller_button_up", to_string(type::controller_button_up)); - ASSERT_EQ("controller_device_added", to_string(type::controller_device_added)); - ASSERT_EQ("controller_device_removed", to_string(type::controller_device_removed)); - ASSERT_EQ("controller_device_remapped", to_string(type::controller_device_remapped)); - - ASSERT_EQ("finger_down", to_string(type::finger_down)); - ASSERT_EQ("finger_up", to_string(type::finger_up)); - ASSERT_EQ("finger_motion", to_string(type::finger_motion)); - - ASSERT_EQ("dollar_gesture", to_string(type::dollar_gesture)); - ASSERT_EQ("dollar_record", to_string(type::dollar_record)); - ASSERT_EQ("multi_gesture", to_string(type::multi_gesture)); - - ASSERT_EQ("clipboard_update", to_string(type::clipboard_update)); - - ASSERT_EQ("drop_file", to_string(type::drop_file)); - ASSERT_EQ("drop_text", to_string(type::drop_text)); - ASSERT_EQ("drop_begin", to_string(type::drop_begin)); - ASSERT_EQ("drop_complete", to_string(type::drop_complete)); - - ASSERT_EQ("audio_device_added", to_string(type::audio_device_added)); - ASSERT_EQ("audio_device_removed", to_string(type::audio_device_removed)); - - ASSERT_EQ("sensor_update", to_string(type::sensor_update)); - - ASSERT_EQ("render_targets_reset", to_string(type::render_targets_reset)); - ASSERT_EQ("render_device_reset", to_string(type::render_device_reset)); - - ASSERT_EQ("user", to_string(type::user)); - ASSERT_EQ("user", to_string(static_cast(SDL_USEREVENT + 1))); - ASSERT_EQ("user", to_string(static_cast(SDL_LASTEVENT - 1))); - -#if SDL_VERSION_ATLEAST(2, 0, 14) - ASSERT_EQ("locale_changed", to_string(type::locale_changed)); - - ASSERT_EQ("controller_touchpad_down", to_string(type::controller_touchpad_down)); - ASSERT_EQ("controller_touchpad_up", to_string(type::controller_touchpad_up)); - ASSERT_EQ("controller_touchpad_motion", to_string(type::controller_touchpad_motion)); - ASSERT_EQ("controller_sensor_update", to_string(type::controller_sensor_update)); -#endif // SDL_VERSION_ATLEAST(2, 0, 14) - - std::cout << "event_type::app_low_memory == " << type::app_low_memory << '\n'; -} diff --git a/test/unit-tests/event/gesture/dollar_gesture_event_test.cpp b/test/unit-tests/event/gesture/dollar_gesture_event_test.cpp deleted file mode 100644 index 39884cd02..000000000 --- a/test/unit-tests/event/gesture/dollar_gesture_event_test.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/misc_events.hpp" - -TEST(DollarGestureEvent, Defaults) -{ - cen::dollar_gesture_event event; - ASSERT_EQ(cen::event_type::dollar_gesture, event.type()); -} - -TEST(DollarGestureEvent, SetTouchId) -{ - cen::dollar_gesture_event event; - - constexpr auto id = 4; - event.set_touch_id(id); - - ASSERT_EQ(id, event.touch_id()); -} - -TEST(DollarGestureEvent, SetGestureId) -{ - cen::dollar_gesture_event event; - - constexpr auto id = 81; - event.set_gesture_id(id); - - ASSERT_EQ(id, event.gesture_id()); -} - -TEST(DollarGestureEvent, SetFingers) -{ - cen::dollar_gesture_event event; - - constexpr Uint32 fingers = 2; - event.set_fingers(fingers); - - ASSERT_EQ(fingers, event.finger_count()); -} - -TEST(DollarGestureEvent, SetError) -{ - cen::dollar_gesture_event event; - - constexpr auto error = 5.1f; - event.set_error(error); - - ASSERT_EQ(error, event.error()); -} - -TEST(DollarGestureEvent, SetX) -{ - cen::dollar_gesture_event event; - - constexpr auto x = 24.8f; - event.set_x(x); - - ASSERT_EQ(x, event.x()); -} - -TEST(DollarGestureEvent, SetY) -{ - cen::dollar_gesture_event event; - - constexpr auto y = -12.9f; - event.set_y(y); - - ASSERT_EQ(y, event.y()); -} - -TEST(DollarGestureEvent, TouchId) -{ - SDL_DollarGestureEvent sdl; - sdl.touchId = 9; - - const cen::dollar_gesture_event event {sdl}; - ASSERT_EQ(sdl.touchId, event.touch_id()); -} - -TEST(DollarGestureEvent, GestureId) -{ - SDL_DollarGestureEvent sdl; - sdl.gestureId = 1; - - const cen::dollar_gesture_event event {sdl}; - ASSERT_EQ(sdl.gestureId, event.gesture_id()); -} - -TEST(DollarGestureEvent, FingerCount) -{ - SDL_DollarGestureEvent sdl; - sdl.numFingers = 3; - - const cen::dollar_gesture_event event {sdl}; - ASSERT_EQ(sdl.numFingers, event.finger_count()); -} - -TEST(DollarGestureEvent, Error) -{ - SDL_DollarGestureEvent sdl; - sdl.error = 7.4f; - - const cen::dollar_gesture_event event {sdl}; - ASSERT_EQ(sdl.error, event.error()); -} - -TEST(DollarGestureEvent, X) -{ - SDL_DollarGestureEvent sdl; - sdl.x = 56.8f; - - const cen::dollar_gesture_event event {sdl}; - ASSERT_EQ(sdl.x, event.x()); -} - -TEST(DollarGestureEvent, Y) -{ - SDL_DollarGestureEvent sdl; - sdl.y = 92.3f; - - const cen::dollar_gesture_event event {sdl}; - ASSERT_EQ(sdl.y, event.y()); -} - -TEST(DollarGestureEvent, AsSDLEvent) -{ - const cen::dollar_gesture_event event; - const auto sdl = cen::as_sdl_event(event); - - ASSERT_EQ(sdl.dgesture.type, static_cast(event.type())); - ASSERT_EQ(sdl.dgesture.timestamp, event.timestamp().count()); -} diff --git a/test/unit-tests/event/gesture/multi_gesture_event_test.cpp b/test/unit-tests/event/gesture/multi_gesture_event_test.cpp deleted file mode 100644 index 13746734c..000000000 --- a/test/unit-tests/event/gesture/multi_gesture_event_test.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/misc_events.hpp" - -TEST(MultiGestureEvent, Defaults) -{ - const cen::multi_gesture_event event; - ASSERT_EQ(cen::event_type::multi_gesture, event.type()); -} - -TEST(MultiGestureEvent, SetTouchId) -{ - cen::multi_gesture_event event; - - event.set_touch_id(3); - ASSERT_EQ(3, event.touch_id()); -} - -TEST(MultiGestureEvent, SetDeltaTheta) -{ - cen::multi_gesture_event event; - - event.set_delta_theta(65); - ASSERT_EQ(65, event.delta_theta()); -} - -TEST(MultiGestureEvent, SetDeltaDistance) -{ - cen::multi_gesture_event event; - - event.set_delta_distance(-79); - ASSERT_EQ(-79, event.delta_distance()); -} - -TEST(MultiGestureEvent, SetCenterX) -{ - cen::multi_gesture_event event; - - event.set_center_x(154); - ASSERT_EQ(154, event.center_x()); -} - -TEST(MultiGestureEvent, SetCenterY) -{ - cen::multi_gesture_event event; - - event.set_center_y(867); - ASSERT_EQ(867, event.center_y()); -} - -TEST(MultiGestureEvent, SetFingers) -{ - cen::multi_gesture_event event; - - event.set_finger_count(3); - ASSERT_EQ(3, event.finger_count()); -} - -TEST(MultiGestureEvent, TouchId) -{ - SDL_MultiGestureEvent sdl; - sdl.touchId = 54; - - const cen::multi_gesture_event event {sdl}; - ASSERT_EQ(sdl.touchId, event.touch_id()); -} - -TEST(MultiGestureEvent, DeltaTheta) -{ - SDL_MultiGestureEvent sdl; - sdl.dTheta = 98; - - const cen::multi_gesture_event event {sdl}; - ASSERT_EQ(sdl.dTheta, event.delta_theta()); -} - -TEST(MultiGestureEvent, DeltaDistance) -{ - SDL_MultiGestureEvent sdl; - sdl.dDist = -87; - - const cen::multi_gesture_event event {sdl}; - ASSERT_EQ(sdl.dDist, event.delta_distance()); -} - -TEST(MultiGestureEvent, CenterX) -{ - SDL_MultiGestureEvent sdl; - sdl.x = 564; - - const cen::multi_gesture_event event {sdl}; - ASSERT_EQ(sdl.x, event.center_x()); -} - -TEST(MultiGestureEvent, CenterY) -{ - SDL_MultiGestureEvent sdl; - sdl.y = 913; - - const cen::multi_gesture_event event {sdl}; - ASSERT_EQ(sdl.y, event.center_y()); -} - -TEST(MultiGestureEvent, FingerCount) -{ - SDL_MultiGestureEvent sdl; - sdl.numFingers = 2; - - const cen::multi_gesture_event event {sdl}; - ASSERT_EQ(sdl.numFingers, event.finger_count()); -} - -TEST(MultiGestureEvent, AsSDLEvent) -{ - const cen::multi_gesture_event event; - const auto sdl = cen::as_sdl_event(event); - - ASSERT_EQ(sdl.mgesture.type, cen::to_underlying(event.type())); - ASSERT_EQ(sdl.mgesture.timestamp, event.timestamp().count()); -} diff --git a/test/unit-tests/event/joystick/joy_axis_event_test.cpp b/test/unit-tests/event/joystick/joy_axis_event_test.cpp deleted file mode 100644 index fb9ec8dcd..000000000 --- a/test/unit-tests/event/joystick/joy_axis_event_test.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/joystick_events.hpp" - -TEST(JoyAxisEvent, Defaults) -{ - const cen::joy_axis_event event; - ASSERT_EQ(cen::event_type::joy_axis_motion, event.type()); -} - -TEST(JoyAxisEvent, SetWhich) -{ - cen::joy_axis_event event; - - const SDL_JoystickID id = 3; - event.set_which(id); - - ASSERT_EQ(id, event.which()); -} - -TEST(JoyAxisEvent, SetAxis) -{ - cen::joy_axis_event event; - - const cen::uint8 axis = 42; - event.set_axis(axis); - - ASSERT_EQ(axis, event.axis()); -} - -TEST(JoyAxisEvent, SetValue) -{ - cen::joy_axis_event event; - - const cen::int16 value = 4'234; - event.set_value(value); - - ASSERT_EQ(value, event.value()); -} - -TEST(JoyAxisEvent, AsSDLEvent) -{ - const cen::joy_axis_event event; - const auto sdl = cen::as_sdl_event(event); - - ASSERT_EQ(sdl.jaxis.type, cen::to_underlying(event.type())); - ASSERT_EQ(sdl.jaxis.timestamp, event.timestamp().count()); -} diff --git a/test/unit-tests/event/joystick/joy_ball_event_test.cpp b/test/unit-tests/event/joystick/joy_ball_event_test.cpp deleted file mode 100644 index 423d61650..000000000 --- a/test/unit-tests/event/joystick/joy_ball_event_test.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/joystick_events.hpp" - -TEST(JoyBallEvent, Defaults) -{ - const cen::joy_ball_event event; - ASSERT_EQ(cen::event_type::joy_ball_motion, event.type()); -} - -TEST(JoyBallEvent, SetWhich) -{ - cen::joy_ball_event event; - - const SDL_JoystickID id = 5; - event.set_which(id); - - ASSERT_EQ(id, event.which()); -} - -TEST(JoyBallEvent, SetBall) -{ - cen::joy_ball_event event; - - const cen::uint8 ball = 6; - event.set_ball(ball); - - ASSERT_EQ(ball, event.ball()); -} - -TEST(JoyBallEvent, SetDX) -{ - cen::joy_ball_event event; - - const cen::int16 dx = 173; - event.set_dx(dx); - - ASSERT_EQ(dx, event.dx()); -} - -TEST(JoyBallEvent, SetDY) -{ - cen::joy_ball_event event; - - const cen::int16 dy = -57; - event.set_dy(dy); - - ASSERT_EQ(dy, event.dy()); -} - -TEST(JoyBallEvent, AsSDLEvent) -{ - const cen::joy_ball_event event; - const auto underlying = cen::as_sdl_event(event); - - ASSERT_EQ(underlying.jball.type, cen::to_underlying(event.type())); - ASSERT_EQ(underlying.jball.timestamp, event.timestamp().count()); -} diff --git a/test/unit-tests/event/joystick/joy_battery_event_test.cpp b/test/unit-tests/event/joystick/joy_battery_event_test.cpp deleted file mode 100644 index 2dd443c1b..000000000 --- a/test/unit-tests/event/joystick/joy_battery_event_test.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/joystick_events.hpp" - -#if SDL_VERSION_ATLEAST(2, 24, 0) - -TEST(JoyBatteryEvent, Defaults) -{ - const cen::joy_battery_event event; - ASSERT_EQ(cen::event_type::joy_battery_updated, event.type()); -} - -TEST(JoyBatteryEvent, SetWhich) -{ - cen::joy_battery_event event; - - const SDL_JoystickID id = 42; - event.set_which(id); - - ASSERT_EQ(id, event.which()); -} - -TEST(JoyBatteryEvent, SetPowerLevel) -{ - cen::joy_battery_event event; - - const auto level = cen::joystick_power::medium; - event.set_power_level(level); - - ASSERT_EQ(level, event.power_level()); -} - -TEST(JoyBatteryEvent, AsSDLEvent) -{ - const cen::joy_battery_event event; - const auto underlying = cen::as_sdl_event(event); - - ASSERT_EQ(underlying.jbattery.type, cen::to_underlying(event.type())); - ASSERT_EQ(underlying.jbattery.timestamp, event.timestamp().count()); -} - -#endif // SDL_VERSION_ATLEAST(2, 24, 0) diff --git a/test/unit-tests/event/joystick/joy_button_event_test.cpp b/test/unit-tests/event/joystick/joy_button_event_test.cpp deleted file mode 100644 index 3648a3717..000000000 --- a/test/unit-tests/event/joystick/joy_button_event_test.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/joystick_events.hpp" - -TEST(JoyButtonEvent, Defaults) -{ - const cen::joy_button_event event; - ASSERT_EQ(cen::event_type::joy_button_down, event.type()); -} - -TEST(JoyButtonEvent, SetWhich) -{ - cen::joy_button_event event; - - const SDL_JoystickID id = 92; - event.set_which(id); - - ASSERT_EQ(id, event.which()); -} - -TEST(JoyButtonEvent, SetButton) -{ - cen::joy_button_event event; - - const cen::uint8 button = 44; - event.set_button(button); - - ASSERT_EQ(button, event.button()); -} - -TEST(JoyButtonEvent, SetState) -{ - cen::joy_button_event event; - - event.set_state(cen::button_state::pressed); - - ASSERT_EQ(cen::button_state::pressed, event.state()); - ASSERT_TRUE(event.is_pressed()); - ASSERT_FALSE(event.is_released()); - - event.set_state(cen::button_state::released); - - ASSERT_EQ(cen::button_state::released, event.state()); - ASSERT_TRUE(event.is_released()); - ASSERT_FALSE(event.is_pressed()); -} - -TEST(JoyButtonEvent, AsSDLEvent) -{ - const cen::joy_button_event event; - const auto sdl = cen::as_sdl_event(event); - - ASSERT_EQ(sdl.jbutton.type, cen::to_underlying(event.type())); - ASSERT_EQ(sdl.jbutton.timestamp, event.timestamp().count()); -} diff --git a/test/unit-tests/event/joystick/joy_device_event_test.cpp b/test/unit-tests/event/joystick/joy_device_event_test.cpp deleted file mode 100644 index f7cb6e89d..000000000 --- a/test/unit-tests/event/joystick/joy_device_event_test.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/joystick_events.hpp" - -TEST(JoyDeviceEvent, Defaults) -{ - const cen::joy_device_event event; - ASSERT_EQ(cen::event_type::joy_device_added, event.type()); -} - -TEST(JoyDeviceEvent, SetWhich) -{ - cen::joy_device_event event; - - const cen::int32 which = 84; - event.set_which(which); - - ASSERT_EQ(which, event.which()); -} - -TEST(JoyDeviceEvent, AsSDLEvent) -{ - const cen::joy_device_event event; - const auto sdl = cen::as_sdl_event(event); - - ASSERT_EQ(sdl.jdevice.type, cen::to_underlying(event.type())); - ASSERT_EQ(sdl.jdevice.timestamp, event.timestamp().count()); -} diff --git a/test/unit-tests/event/joystick/joy_hat_event_test.cpp b/test/unit-tests/event/joystick/joy_hat_event_test.cpp deleted file mode 100644 index 605f0f107..000000000 --- a/test/unit-tests/event/joystick/joy_hat_event_test.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/joystick_events.hpp" - -TEST(JoyHatEvent, Defaults) -{ - const cen::joy_hat_event event; - ASSERT_EQ(cen::event_type::joy_hat_motion, event.type()); -} - -TEST(JoyHatEvent, SetHat) -{ - cen::joy_hat_event event; - - const cen::uint8 hat = 7; - event.set_hat(hat); - - ASSERT_EQ(hat, event.hat()); -} - -TEST(JoyHatEvent, SetPosition) -{ - cen::joy_hat_event event; - - event.set_position(cen::joy_hat_position::right); - ASSERT_EQ(cen::joy_hat_position::right, event.position()); -} - -TEST(JoyHatEvent, AsSDLEvent) -{ - const cen::joy_hat_event event; - const auto sdl = cen::as_sdl_event(event); - - ASSERT_EQ(sdl.jhat.type, cen::to_underlying(event.type())); - ASSERT_EQ(sdl.jhat.timestamp, event.timestamp().count()); -} diff --git a/test/unit-tests/event/joystick/joy_hat_position_test.cpp b/test/unit-tests/event/joystick/joy_hat_position_test.cpp deleted file mode 100644 index f22af876c..000000000 --- a/test/unit-tests/event/joystick/joy_hat_position_test.cpp +++ /dev/null @@ -1,61 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // cout - -#include "centurion/events/joystick_events.hpp" - -using position = cen::joy_hat_position; - -TEST(JoyHatPosition, Values) -{ - ASSERT_EQ(SDL_HAT_LEFTUP, to_underlying(position::left_up)); - ASSERT_EQ(SDL_HAT_LEFT, to_underlying(position::left)); - ASSERT_EQ(SDL_HAT_LEFTDOWN, to_underlying(position::left_down)); - ASSERT_EQ(SDL_HAT_UP, to_underlying(position::up)); - ASSERT_EQ(SDL_HAT_CENTERED, to_underlying(position::centered)); - ASSERT_EQ(SDL_HAT_DOWN, to_underlying(position::down)); - ASSERT_EQ(SDL_HAT_RIGHTUP, to_underlying(position::right_up)); - ASSERT_EQ(SDL_HAT_RIGHT, to_underlying(position::right)); - ASSERT_EQ(SDL_HAT_RIGHTDOWN, to_underlying(position::right_down)); -} - -TEST(JoyHatPosition, ToString) -{ - ASSERT_THROW(to_string(static_cast(SDL_HAT_RIGHTDOWN + 1)), cen::exception); - - ASSERT_EQ("left_up", to_string(position::left_up)); - ASSERT_EQ("left", to_string(position::left)); - ASSERT_EQ("left_down", to_string(position::left_down)); - ASSERT_EQ("up", to_string(position::up)); - ASSERT_EQ("centered", to_string(position::centered)); - ASSERT_EQ("down", to_string(position::down)); - ASSERT_EQ("right_up", to_string(position::right_up)); - ASSERT_EQ("right", to_string(position::right)); - ASSERT_EQ("right_down", to_string(position::right_down)); - - std::cout << "joystick_hat_position::left == " << position::left << '\n'; -} diff --git a/test/unit-tests/event/misc/display_event_id_test.cpp b/test/unit-tests/event/misc/display_event_id_test.cpp deleted file mode 100644 index c72519d2c..000000000 --- a/test/unit-tests/event/misc/display_event_id_test.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // cout - -#include "centurion/events/misc_events.hpp" - -#if SDL_VERSION_ATLEAST(2, 0, 14) - -using id = cen::display_event_id; - -TEST(DisplayEventID, Values) -{ - ASSERT_EQ(SDL_DISPLAYEVENT_NONE, to_underlying(id::none)); - ASSERT_EQ(SDL_DISPLAYEVENT_ORIENTATION, to_underlying(id::orientation)); - ASSERT_EQ(SDL_DISPLAYEVENT_CONNECTED, to_underlying(id::connected)); - ASSERT_EQ(SDL_DISPLAYEVENT_DISCONNECTED, to_underlying(id::disconnected)); -} - -TEST(DisplayEventID, ToString) -{ - ASSERT_THROW(to_string(static_cast(4)), cen::exception); - - ASSERT_EQ("none", to_string(id::none)); - ASSERT_EQ("orientation", to_string(id::orientation)); - ASSERT_EQ("connected", to_string(id::connected)); - ASSERT_EQ("disconnected", to_string(id::disconnected)); - - std::cout << "display_event_id::connected == " << id::connected << '\n'; -} - -#endif // SDL_VERSION_ATLEAST(2, 0, 14) \ No newline at end of file diff --git a/test/unit-tests/event/misc/display_event_test.cpp b/test/unit-tests/event/misc/display_event_test.cpp deleted file mode 100644 index 56f1cfcaf..000000000 --- a/test/unit-tests/event/misc/display_event_test.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/misc_events.hpp" - -#if SDL_VERSION_ATLEAST(2, 0, 14) - -TEST(DisplayEvent, Defaults) -{ - const cen::display_event event; - ASSERT_EQ(cen::event_type::display, event.type()); - ASSERT_EQ(cen::display_event_id::none, event.event_id()); - ASSERT_EQ(0u, event.index()); - ASSERT_EQ(0, event.data1()); -} - -TEST(DisplayEvent, SetEventID) -{ - cen::display_event event; - - event.set_event_id(cen::display_event_id::orientation); - ASSERT_EQ(cen::display_event_id::orientation, event.event_id()); - - event.set_event_id(cen::display_event_id::connected); - ASSERT_EQ(cen::display_event_id::connected, event.event_id()); - - event.set_event_id(cen::display_event_id::disconnected); - ASSERT_EQ(cen::display_event_id::disconnected, event.event_id()); -} - -TEST(DisplayEvent, SetIndex) -{ - cen::display_event event; - - const cen::uint32 index = 42; - event.set_index(index); - - ASSERT_EQ(index, event.index()); -} - -TEST(DisplayEvent, SetData1) -{ - cen::display_event event; - - event.set_data1(SDL_ORIENTATION_LANDSCAPE); - ASSERT_EQ(SDL_ORIENTATION_LANDSCAPE, event.data1()); -} - -TEST(DisplayEvent, AsSdlEvent) -{ - cen::display_event event; - event.set_index(123u); - event.set_event_id(cen::display_event_id::connected); - event.set_data1(5); - - const auto converted = cen::as_sdl_event(event); - ASSERT_EQ(SDL_DISPLAYEVENT, static_cast(converted.display.type)); - ASSERT_EQ(123u, converted.display.display); - ASSERT_EQ(SDL_DISPLAYEVENT_CONNECTED, converted.display.event); - ASSERT_EQ(5, converted.display.data1); -} - -#endif // SDL_VERSION_ATLEAST(2, 0, 14) \ No newline at end of file diff --git a/test/unit-tests/event/misc/drop_event_test.cpp b/test/unit-tests/event/misc/drop_event_test.cpp deleted file mode 100644 index 2d365ba58..000000000 --- a/test/unit-tests/event/misc/drop_event_test.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/misc_events.hpp" - -TEST(DropEvent, Defaults) -{ - const cen::drop_event event; - ASSERT_EQ(cen::event_type::drop_file, event.type()); - - ASSERT_EQ(nullptr, event.file()); - ASSERT_EQ(0u, event.window_id()); - ASSERT_FALSE(event.will_free_file()); -} - -TEST(DropEvent, SetWillFreeFile) -{ - cen::drop_event event; - - event.set_will_free_file(true); - ASSERT_TRUE(event.will_free_file()); - - event.set_will_free_file(false); - ASSERT_FALSE(event.will_free_file()); -} - -TEST(DropEvent, SetFile) -{ - cen::drop_event event; - ASSERT_NO_THROW(event.set_file(nullptr)); - - event.set_will_free_file(true); - ASSERT_TRUE(event.will_free_file()); - - /* This is the only time in the tests that a drop event should free the file, - check the code coverage reports in order to see if it's freed. */ - event.set_file(static_cast(SDL_malloc(sizeof(char)))); -} - -TEST(DropEvent, SetWindowID) -{ - cen::drop_event event; - - event.set_window_id(84); - ASSERT_EQ(84u, event.window_id()); -} - -TEST(DropEvent, AsSDLEvent) -{ - const cen::drop_event event; - const auto underlying = cen::as_sdl_event(event); - - ASSERT_EQ(underlying.drop.type, cen::to_underlying(event.type())); - ASSERT_EQ(underlying.drop.timestamp, event.timestamp().count()); -} diff --git a/test/unit-tests/event/misc/keyboard_event_test.cpp b/test/unit-tests/event/misc/keyboard_event_test.cpp deleted file mode 100644 index d5ddbacd1..000000000 --- a/test/unit-tests/event/misc/keyboard_event_test.cpp +++ /dev/null @@ -1,202 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/misc_events.hpp" - -TEST(KeyboardEvent, Defaults) -{ - const cen::keyboard_event event; - ASSERT_EQ(cen::event_type::key_down, event.type()); -} - -TEST(KeyboardEvent, SetScan) -{ - cen::keyboard_event event; - - event.set_scan(cen::scancodes::b); - ASSERT_EQ(cen::scancodes::b, event.scan()); -} - -TEST(KeyboardEvent, SetKey) -{ - cen::keyboard_event event; - - event.set_key(cen::keycodes::n); - ASSERT_EQ(cen::keycodes::n, event.key()); -} - -TEST(KeyboardEvent, SetModifier) -{ - cen::keyboard_event event; - - const auto shift = cen::key_mod::lshift; - const auto caps = cen::key_mod::caps; - - event.set_modifier(shift, true); - ASSERT_TRUE(event.is_active(shift)); - - event.set_modifier(caps, true); - ASSERT_TRUE(event.is_active(shift)); - ASSERT_TRUE(event.is_active(caps)); - - event.set_modifier(shift, false); - ASSERT_FALSE(event.is_active(shift)); - ASSERT_TRUE(event.is_active(caps)); -} - -TEST(KeyboardEvent, SetRepeated) -{ - cen::keyboard_event event; - - event.set_repeated(true); - ASSERT_TRUE(event.repeated()); - - event.set_repeated(false); - ASSERT_FALSE(event.repeated()); -} - -TEST(KeyboardEvent, SetWindowID) -{ - cen::keyboard_event event; - - event.set_window_id(79); - ASSERT_EQ(79u, event.window_id()); -} - -TEST(KeyboardEvent, SetState) -{ - cen::keyboard_event event; - - event.set_state(cen::button_state::pressed); - ASSERT_EQ(cen::button_state::pressed, event.state()); - ASSERT_TRUE(event.pressed()); - ASSERT_FALSE(event.released()); - - event.set_state(cen::button_state::released); - ASSERT_EQ(cen::button_state::released, event.state()); - ASSERT_TRUE(event.released()); - ASSERT_FALSE(event.pressed()); -} - -TEST(KeyboardEvent, IsActive) -{ - cen::keyboard_event event; - event.set_scan(cen::scancodes::q); - event.set_key(cen::keycodes::d); - - ASSERT_TRUE(event.is_active(cen::scancodes::q)); - ASSERT_TRUE(event.is_active(cen::keycodes::d)); - - ASSERT_FALSE(event.is_active(cen::scancodes::o)); - ASSERT_FALSE(event.is_active(cen::keycodes::x)); -} - -TEST(KeyboardEvent, IsOnlyActive) -{ - cen::keyboard_event event; - ASSERT_TRUE(event.is_active(cen::key_mod::none)); - ASSERT_TRUE(event.is_only_active(cen::key_mod::none)); - ASSERT_FALSE(event.is_active(cen::key_mod::shift)); - ASSERT_FALSE(event.is_only_active(cen::key_mod::shift)); - - event.set_modifier(cen::key_mod::shift, true); - ASSERT_FALSE(event.is_active(cen::key_mod::none)); - ASSERT_FALSE(event.is_only_active(cen::key_mod::none)); - ASSERT_TRUE(event.is_active(cen::key_mod::shift)); - ASSERT_TRUE(event.is_only_active(cen::key_mod::shift)); - ASSERT_FALSE(event.is_only_active(cen::key_mod::lshift)); - ASSERT_FALSE(event.is_only_active(cen::key_mod::rshift)); - - event.set_modifier(cen::key_mod::alt, true); - ASSERT_FALSE(event.is_active(cen::key_mod::none)); - ASSERT_FALSE(event.is_only_active(cen::key_mod::none)); - ASSERT_TRUE(event.is_active(cen::key_mod::shift)); - ASSERT_TRUE(event.is_active(cen::key_mod::alt)); - ASSERT_FALSE(event.is_only_active(cen::key_mod::shift)); - ASSERT_FALSE(event.is_only_active(cen::key_mod::alt)); - - event.set_modifier(cen::key_mod::alt, false); - event.set_modifier(cen::key_mod::rshift, false); - ASSERT_FALSE(event.is_active(cen::key_mod::none)); - ASSERT_FALSE(event.is_only_active(cen::key_mod::none)); - ASSERT_TRUE(event.is_active(cen::key_mod::shift)); - ASSERT_TRUE(event.is_active(cen::key_mod::lshift)); - ASSERT_FALSE(event.is_active(cen::key_mod::rshift)); - ASSERT_FALSE(event.is_only_active(cen::key_mod::shift)); - ASSERT_TRUE(event.is_only_active(cen::key_mod::lshift)); - ASSERT_FALSE(event.is_only_active(cen::key_mod::rshift)); -} - -TEST(KeyboardEvent, IsOnlyAnyOfActive) -{ - cen::keyboard_event event; - ASSERT_TRUE(event.is_active(cen::key_mod::none)); - ASSERT_TRUE(event.is_only_active(cen::key_mod::none)); - ASSERT_TRUE(event.is_only_subset_active(cen::key_mod::none)); - ASSERT_FALSE(event.is_active(cen::key_mod::shift)); - ASSERT_FALSE(event.is_only_active(cen::key_mod::shift)); - ASSERT_FALSE(event.is_only_subset_active(cen::key_mod::shift)); - - event.set_modifier(cen::key_mod::lshift, true); - ASSERT_TRUE(event.is_active(cen::key_mod::shift)); - ASSERT_FALSE(event.is_only_active(cen::key_mod::shift)); - ASSERT_TRUE(event.is_only_subset_active(cen::key_mod::shift)); - ASSERT_TRUE(event.is_only_subset_active(cen::key_mod::lshift)); - - event.set_modifier(cen::key_mod::rgui, true); - ASSERT_TRUE(event.is_active(cen::key_mod::shift)); - ASSERT_FALSE(event.is_only_active(cen::key_mod::shift)); - ASSERT_FALSE(event.is_only_subset_active(cen::key_mod::shift)); - - ASSERT_TRUE(event.is_only_active(cen::key_mod::lshift | cen::key_mod::rgui)); - ASSERT_TRUE(event.is_only_subset_active(cen::key_mod::lshift | cen::key_mod::rgui)); - ASSERT_TRUE(event.is_only_subset_active(cen::key_mod::shift | cen::key_mod::gui)); -} - -TEST(KeyboardEvent, IsActiveModifier) -{ - SDL_KeyboardEvent sdl {}; - - SDL_Keysym keysym {}; - keysym.mod = KMOD_LALT | KMOD_CAPS; - - sdl.keysym = keysym; - - const cen::keyboard_event event {sdl}; - - // Check that multiple key modifiers can be active at the same time - ASSERT_TRUE(event.is_active(cen::key_mod::lalt)); - ASSERT_TRUE(event.is_active(cen::key_mod::caps)); -} - -TEST(keyboard_event, AsSDLEvent) -{ - const cen::keyboard_event event; - const auto underlying = cen::as_sdl_event(event); - - ASSERT_EQ(underlying.key.type, cen::to_underlying(event.type())); - ASSERT_EQ(underlying.key.timestamp, event.timestamp().count()); -} diff --git a/test/unit-tests/event/misc/quit_event_test.cpp b/test/unit-tests/event/misc/quit_event_test.cpp deleted file mode 100644 index 48fa4e241..000000000 --- a/test/unit-tests/event/misc/quit_event_test.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/misc_events.hpp" - -TEST(QuitEvent, Defaults) -{ - const cen::quit_event event; - ASSERT_EQ(cen::event_type::quit, event.type()); -} - -TEST(QuitEvent, AsSDLEvent) -{ - const cen::quit_event event; - const auto sdl = cen::as_sdl_event(event); - - ASSERT_EQ(sdl.quit.type, cen::to_underlying(event.type())); - ASSERT_EQ(sdl.quit.timestamp, event.timestamp().count()); -} diff --git a/test/unit-tests/event/misc/sensor_event_test.cpp b/test/unit-tests/event/misc/sensor_event_test.cpp deleted file mode 100644 index 7665541ff..000000000 --- a/test/unit-tests/event/misc/sensor_event_test.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/misc_events.hpp" - -TEST(SensorEvent, Defaults) -{ - const cen::sensor_event event; - ASSERT_EQ(cen::event_type::sensor_update, event.type()); - ASSERT_EQ(0, event.which()); -} - -TEST(SensorEvent, SetWhich) -{ - cen::sensor_event event; - - const auto id = 42; - event.set_which(id); - - ASSERT_EQ(id, event.which()); -} - -TEST(SensorEvent, SetData) -{ - cen::sensor_event event; - - const std::array values = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f}; - event.set_data(values); - - ASSERT_EQ(1.0f, event.data().at(0)); - ASSERT_EQ(2.0f, event.data().at(1)); - ASSERT_EQ(3.0f, event.data().at(2)); - ASSERT_EQ(4.0f, event.data().at(3)); - ASSERT_EQ(5.0f, event.data().at(4)); - ASSERT_EQ(6.0f, event.data().at(5)); -} - -TEST(SensorEvent, AsSDLEvent) -{ - const cen::sensor_event event; - const auto sdl = cen::as_sdl_event(event); - - ASSERT_EQ(sdl.sensor.type, cen::to_underlying(event.type())); - ASSERT_EQ(sdl.sensor.which, event.which()); - ASSERT_EQ(sdl.sensor.timestamp, event.timestamp().count()); -} diff --git a/test/unit-tests/event/misc/touch_finger_event_test.cpp b/test/unit-tests/event/misc/touch_finger_event_test.cpp deleted file mode 100644 index af2f8b15a..000000000 --- a/test/unit-tests/event/misc/touch_finger_event_test.cpp +++ /dev/null @@ -1,258 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/misc_events.hpp" - -TEST(TouchFingerEvent, Defaults) -{ - cen::touch_finger_event event; - ASSERT_EQ(cen::event_type::finger_down, event.type()); -} - -TEST(TouchFingerEvent, SetTouchId) -{ - cen::touch_finger_event event; - - constexpr auto id = 8; - event.set_touch_id(id); - - ASSERT_EQ(id, event.touch_id()); -} - -TEST(TouchFingerEvent, SetFingerId) -{ - cen::touch_finger_event event; - - constexpr auto id = 14; - event.set_finger_id(id); - - ASSERT_EQ(id, event.finger_id()); -} - -#if SDL_VERSION_ATLEAST(2, 0, 12) - -TEST(TouchFingerEvent, SetWindowId) -{ - cen::touch_finger_event event; - - constexpr Uint32 id = 32; - event.set_window_id(id); - - ASSERT_EQ(id, event.window_id()); -} - -TEST(TouchFingerEvent, WindowId) -{ - SDL_TouchFingerEvent sdl {}; - sdl.windowID = 7; - - const cen::touch_finger_event event {sdl}; - ASSERT_EQ(sdl.windowID, event.window_id()); -} - -#endif // SDL_VERSION_ATLEAST(2, 0, 12) - -TEST(TouchFingerEvent, SetX) -{ - cen::touch_finger_event event; - - { // Overflow - event.set_x(1.1f); - ASSERT_EQ(1, event.x()); - } - - { // Underflow - event.set_x(-0.1f); - ASSERT_EQ(0, event.x()); - } - - { // Good value - constexpr auto x = 0.4f; - event.set_x(x); - - ASSERT_EQ(x, event.x()); - } -} - -TEST(TouchFingerEvent, SetY) -{ - cen::touch_finger_event event; - - { // Overflow - event.set_y(1.1f); - ASSERT_EQ(1, event.y()); - } - - { // Underflow - event.set_y(-0.1f); - ASSERT_EQ(0, event.y()); - } - - { // Good value - constexpr auto y = 0.9f; - event.set_y(y); - - ASSERT_EQ(y, event.y()); - } -} - -TEST(TouchFingerEvent, SetDx) -{ - cen::touch_finger_event event; - - { // Overflow - event.set_dx(1.1f); - ASSERT_EQ(1, event.dx()); - } - - { // Underflow - event.set_dx(-1.1f); - ASSERT_EQ(-1, event.dx()); - } - - { // Good value - constexpr auto dx = -0.4f; - event.set_dx(dx); - - ASSERT_EQ(dx, event.dx()); - } -} - -TEST(TouchFingerEvent, SetDy) -{ - cen::touch_finger_event event; - - { // Overflow - event.set_dy(1.1f); - ASSERT_EQ(1, event.dy()); - } - - { // Underflow - event.set_dy(-1.1f); - ASSERT_EQ(-1, event.dy()); - } - - { // Good value - constexpr auto dy = 0.75f; - event.set_dy(dy); - - ASSERT_EQ(dy, event.dy()); - } -} - -TEST(TouchFingerEvent, SetPressure) -{ - cen::touch_finger_event event; - - { // Overflow - event.set_pressure(1.1f); - ASSERT_EQ(1, event.pressure()); - } - - { // Underflow - event.set_pressure(-0.1f); - ASSERT_EQ(0, event.pressure()); - } - - { // Good value - constexpr auto pressure = 0.75f; - event.set_pressure(pressure); - - ASSERT_EQ(pressure, event.pressure()); - } -} - -TEST(TouchFingerEvent, TouchId) -{ - SDL_TouchFingerEvent sdl {}; - sdl.touchId = 4; - - const cen::touch_finger_event event {sdl}; - ASSERT_EQ(sdl.touchId, event.touch_id()); -} - -TEST(TouchFingerEvent, FingerId) -{ - SDL_TouchFingerEvent sdl {}; - sdl.fingerId = 18; - - const cen::touch_finger_event event {sdl}; - ASSERT_EQ(sdl.fingerId, event.finger_id()); -} - -TEST(TouchFingerEvent, X) -{ - SDL_TouchFingerEvent sdl {}; - sdl.x = 0.4f; - - const cen::touch_finger_event event {sdl}; - ASSERT_EQ(sdl.x, event.x()); -} - -TEST(TouchFingerEvent, Y) -{ - SDL_TouchFingerEvent sdl {}; - sdl.y = 0.8f; - - const cen::touch_finger_event event {sdl}; - ASSERT_EQ(sdl.y, event.y()); -} - -TEST(TouchFingerEvent, Dx) -{ - SDL_TouchFingerEvent sdl {}; - sdl.dx = -0.9f; - - const cen::touch_finger_event event {sdl}; - ASSERT_EQ(sdl.dx, event.dx()); -} - -TEST(TouchFingerEvent, Dy) -{ - SDL_TouchFingerEvent sdl {}; - sdl.dy = 0.2f; - - const cen::touch_finger_event event {sdl}; - ASSERT_EQ(sdl.dy, event.dy()); -} - -TEST(TouchFingerEvent, Pressure) -{ - SDL_TouchFingerEvent sdl {}; - sdl.pressure = 0.6f; - - const cen::touch_finger_event event {sdl}; - ASSERT_EQ(sdl.pressure, event.pressure()); -} - -TEST(TouchFingerEvent, AsSDLEvent) -{ - const cen::touch_finger_event event; - const auto sdl = cen::as_sdl_event(event); - - ASSERT_EQ(sdl.tfinger.type, cen::to_underlying(event.type())); - ASSERT_EQ(sdl.tfinger.timestamp, event.timestamp().count()); -} diff --git a/test/unit-tests/event/misc/user_event_test.cpp b/test/unit-tests/event/misc/user_event_test.cpp deleted file mode 100644 index 62a753855..000000000 --- a/test/unit-tests/event/misc/user_event_test.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/misc_events.hpp" - -TEST(UserEvent, Defaults) -{ - const cen::user_event event; - - ASSERT_EQ(0, event.code()); - ASSERT_EQ(0u, event.window_id()); - - ASSERT_EQ(nullptr, event.data1()); - ASSERT_EQ(nullptr, event.data2()); -} - -TEST(UserEvent, SetWindowID) -{ - cen::user_event event; - - const cen::uint32 id = 123; - event.set_window_id(id); - - ASSERT_EQ(id, event.window_id()); -} - -TEST(UserEvent, SetCode) -{ - cen::user_event event; - - const cen::int32 code = 13; - event.set_code(code); - - ASSERT_EQ(code, event.code()); -} - -TEST(UserEvent, SetData1) -{ - cen::user_event event; - const auto& ref = event; - - int i = 42; - event.set_data1(&i); - - ASSERT_EQ(&i, event.data1()); - ASSERT_EQ(&i, ref.data1()); - ASSERT_EQ(nullptr, event.data2()); -} - -TEST(UserEvent, SetData2) -{ - cen::user_event event; - const auto& ref = event; - - int i = 42; - event.set_data2(&i); - - ASSERT_EQ(&i, event.data2()); - ASSERT_EQ(&i, ref.data2()); - ASSERT_EQ(nullptr, event.data1()); -} - -TEST(UserEvent, AsSDLEvent) -{ - const cen::user_event event; - const auto underlying = cen::as_sdl_event(event); - - ASSERT_EQ(underlying.user.type, cen::to_underlying(event.type())); - ASSERT_EQ(underlying.user.timestamp, event.timestamp().count()); - ASSERT_EQ(underlying.user.code, event.code()); - ASSERT_EQ(underlying.user.windowID, event.window_id()); - ASSERT_EQ(underlying.user.data1, event.data1()); - ASSERT_EQ(underlying.user.data2, event.data2()); -} diff --git a/test/unit-tests/event/mouse/mouse_button_event_test.cpp b/test/unit-tests/event/mouse/mouse_button_event_test.cpp deleted file mode 100644 index 5239a0923..000000000 --- a/test/unit-tests/event/mouse/mouse_button_event_test.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/mouse_events.hpp" - -TEST(MouseButtonEvent, Defaults) -{ - const cen::mouse_button_event event; - ASSERT_EQ(cen::event_type::mouse_button_down, event.type()); -} - -TEST(MouseButtonEvent, SetWindowID) -{ - cen::mouse_button_event event; - - const cen::uint32 id = 64; - event.set_window_id(id); - - ASSERT_EQ(id, event.window_id()); -} - -TEST(MouseButtonEvent, SetWhich) -{ - cen::mouse_button_event event; - - const cen::uint32 which = 17; - event.set_which(which); - - ASSERT_EQ(which, event.which()); -} - -TEST(MouseButtonEvent, SetButton) -{ - cen::mouse_button_event event; - - event.set_button(cen::mouse_button::right); - ASSERT_EQ(cen::mouse_button::right, event.button()); -} - -TEST(MouseButtonEvent, SetState) -{ - cen::mouse_button_event event; - - event.set_state(cen::button_state::pressed); - - ASSERT_EQ(cen::button_state::pressed, event.state()); - ASSERT_TRUE(event.pressed()); - ASSERT_FALSE(event.released()); - - event.set_state(cen::button_state::released); - - ASSERT_EQ(cen::button_state::released, event.state()); - ASSERT_TRUE(event.released()); - ASSERT_FALSE(event.pressed()); -} - -TEST(MouseButtonEvent, SetClicks) -{ - cen::mouse_button_event event; - - const cen::uint8 clicks = 2; - event.set_clicks(clicks); - - ASSERT_EQ(clicks, event.clicks()); -} - -TEST(MouseButtonEvent, SetX) -{ - cen::mouse_button_event event; - - const cen::int32 x = 645; - event.set_x(x); - - ASSERT_EQ(x, event.x()); -} - -TEST(MouseButtonEvent, SetY) -{ - cen::mouse_button_event event; - - const cen::int32 y = 177; - event.set_y(y); - - ASSERT_EQ(y, event.y()); -} - -TEST(MouseButtonEvent, AsSDLEvent) -{ - const cen::mouse_button_event event; - const auto sdl = cen::as_sdl_event(event); - - ASSERT_EQ(sdl.button.type, cen::to_underlying(event.type())); - ASSERT_EQ(sdl.button.timestamp, event.timestamp().count()); -} diff --git a/test/unit-tests/event/mouse/mouse_motion_event_test.cpp b/test/unit-tests/event/mouse/mouse_motion_event_test.cpp deleted file mode 100644 index a75adf605..000000000 --- a/test/unit-tests/event/mouse/mouse_motion_event_test.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/mouse_events.hpp" - -TEST(MouseMotionEvent, Defaults) -{ - const cen::mouse_motion_event event; - ASSERT_EQ(cen::event_type::mouse_motion, event.type()); -} - -TEST(MouseMotionEvent, SetWindowID) -{ - cen::mouse_motion_event event; - - const cen::uint32 id = 8; - event.set_window_id(id); - - ASSERT_EQ(id, event.window_id()); -} - -TEST(MouseMotionEvent, SetWhich) -{ - cen::mouse_motion_event event; - - const cen::uint32 which = 65; - event.set_which(which); - - ASSERT_EQ(which, event.which()); -} - -TEST(MouseMotionEvent, SetState) -{ - cen::mouse_motion_event event; - - event.set_state(SDL_BUTTON_LMASK | SDL_BUTTON_MMASK); - ASSERT_EQ(Uint32 {SDL_BUTTON_LMASK | SDL_BUTTON_MMASK}, event.state()); - - ASSERT_TRUE(event.pressed(cen::mouse_button::left)); - ASSERT_TRUE(event.pressed(cen::mouse_button::middle)); - - ASSERT_FALSE(event.pressed(cen::mouse_button::right)); - ASSERT_FALSE(event.pressed(cen::mouse_button::x1)); - ASSERT_FALSE(event.pressed(cen::mouse_button::x2)); -} - -TEST(MouseMotionEvent, SetX) -{ - cen::mouse_motion_event event; - - const cen::int32 x = 745; - event.set_x(x); - - ASSERT_EQ(x, event.x()); -} - -TEST(MouseMotionEvent, SetY) -{ - cen::mouse_motion_event event; - - const cen::int32 y = 123; - event.set_y(y); - - ASSERT_EQ(y, event.y()); -} - -TEST(MouseMotionEvent, SetDX) -{ - cen::mouse_motion_event event; - - const cen::int32 dx = -456; - event.set_dx(dx); - - ASSERT_EQ(dx, event.dx()); -} - -TEST(MouseMotionEvent, SetDY) -{ - cen::mouse_motion_event event; - - const cen::int32 dy = 835; - event.set_dy(dy); - - ASSERT_EQ(dy, event.dy()); -} - -TEST(MouseMotionEvent, AsSDLEvent) -{ - const cen::mouse_motion_event event; - const auto sdl = cen::as_sdl_event(event); - - ASSERT_EQ(sdl.motion.type, cen::to_underlying(event.type())); - ASSERT_EQ(sdl.motion.timestamp, event.timestamp().count()); -} diff --git a/test/unit-tests/event/mouse/mouse_wheel_direction_test.cpp b/test/unit-tests/event/mouse/mouse_wheel_direction_test.cpp deleted file mode 100644 index 4198182dc..000000000 --- a/test/unit-tests/event/mouse/mouse_wheel_direction_test.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // cout - -#include "centurion/events/mouse_events.hpp" - -using direction = cen::mouse_wheel_direction; - -TEST(MouseWheelDirection, Values) -{ - ASSERT_EQ(SDL_MOUSEWHEEL_NORMAL, to_underlying(direction::normal)); - ASSERT_EQ(SDL_MOUSEWHEEL_FLIPPED, to_underlying(direction::flipped)); -} - -TEST(MouseWheelDirection, ToString) -{ - ASSERT_THROW(to_string(static_cast(3)), cen::exception); - - ASSERT_EQ("normal", to_string(direction::normal)); - ASSERT_EQ("flipped", to_string(direction::flipped)); - - std::cout << "mouse_wheel_direction::normal == " << direction::normal << '\n'; -} diff --git a/test/unit-tests/event/mouse/mouse_wheel_event_test.cpp b/test/unit-tests/event/mouse/mouse_wheel_event_test.cpp deleted file mode 100644 index 865020cdb..000000000 --- a/test/unit-tests/event/mouse/mouse_wheel_event_test.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/mouse_events.hpp" - -TEST(MouseWheelEvent, Defaults) -{ - const cen::mouse_wheel_event event; - ASSERT_EQ(cen::event_type::mouse_wheel, event.type()); -} - -TEST(MouseWheelEvent, SetWindowID) -{ - cen::mouse_wheel_event event; - - const cen::uint32 id = 32; - event.set_window_id(id); - - ASSERT_EQ(id, event.window_id()); -} - -TEST(MouseWheelEvent, SetWhich) -{ - cen::mouse_wheel_event event; - - const cen::uint32 which = 65; - event.set_which(which); - - ASSERT_EQ(which, event.which()); -} - -TEST(MouseWheelEvent, SetX) -{ - cen::mouse_wheel_event event; - - const cen::int32 x = -545; - event.set_x(x); - - ASSERT_EQ(x, event.x()); -} - -TEST(MouseWheelEvent, SetY) -{ - cen::mouse_wheel_event event; - - const cen::int32 y = 725; - event.set_y(y); - - ASSERT_EQ(y, event.y()); -} - -#if SDL_VERSION_ATLEAST(2, 0, 18) - -TEST(MouseWheelEvent, SetPreciseX) -{ - cen::mouse_wheel_event event; - - const float x = 4.5f; - event.set_precise_x(x); - - ASSERT_EQ(x, event.precise_x()); -} - -TEST(MouseWheelEvent, SetPreciseY) -{ - cen::mouse_wheel_event event; - - const float y = -89.3f; - event.set_precise_y(y); - - ASSERT_EQ(y, event.precise_y()); -} - -#endif // SDL_VERSION_ATLEAST(2, 0, 18) - -TEST(MouseWheelEvent, SetDirection) -{ - cen::mouse_wheel_event event; - - event.set_direction(cen::mouse_wheel_direction::flipped); - ASSERT_EQ(cen::mouse_wheel_direction::flipped, event.direction()); -} - -TEST(MouseWheelEvent, AsSDLEvent) -{ - const cen::mouse_wheel_event event; - const auto sdl = cen::as_sdl_event(event); - - ASSERT_EQ(sdl.wheel.type, cen::to_underlying(event.type())); - ASSERT_EQ(sdl.wheel.timestamp, event.timestamp().count()); -} diff --git a/test/unit-tests/event/text/text_editing_event_test.cpp b/test/unit-tests/event/text/text_editing_event_test.cpp deleted file mode 100644 index a7fac4158..000000000 --- a/test/unit-tests/event/text/text_editing_event_test.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/misc_events.hpp" - -TEST(TextEditingEvent, Defaults) -{ - cen::text_editing_event event; - ASSERT_EQ(cen::event_type::text_editing, event.type()); -} - -TEST(TextEditingEvent, SetWindowId) -{ - cen::text_editing_event event; - - constexpr Uint32 id = 8; - event.set_window_id(id); - - ASSERT_EQ(id, event.window_id()); -} - -TEST(TextEditingEvent, SetStart) -{ - cen::text_editing_event event; - - constexpr auto start = 4; - event.set_start(start); - - ASSERT_EQ(start, event.start()); -} - -TEST(TextEditingEvent, SetLength) -{ - cen::text_editing_event event; - - constexpr auto length = 9; - event.set_length(length); - - ASSERT_EQ(length, event.length()); - - event.set_length(-1); - ASSERT_EQ(0, event.length()); - - event.set_length(33); - ASSERT_EQ(32, event.length()); -} - -TEST(TextEditingEvent, WindowId) -{ - SDL_TextEditingEvent sdl {}; - sdl.windowID = 7; - - const cen::text_editing_event event {sdl}; - ASSERT_EQ(sdl.windowID, event.window_id()); -} - -TEST(TextEditingEvent, Start) -{ - SDL_TextEditingEvent sdl {}; - sdl.start = 4; - - const cen::text_editing_event event {sdl}; - ASSERT_EQ(sdl.start, event.start()); -} - -TEST(TextEditingEvent, Length) -{ - { // Good length - SDL_TextEditingEvent sdl {}; - sdl.length = 4; - - const cen::text_editing_event event {sdl}; - ASSERT_EQ(sdl.length, event.length()); - } - - { // Underflow length - SDL_TextEditingEvent sdl {}; - sdl.length = -1; - - const cen::text_editing_event event {sdl}; - ASSERT_EQ(0, event.length()); - } - - { // Overflow length - SDL_TextEditingEvent sdl {}; - sdl.length = 33; - - const cen::text_editing_event event {sdl}; - ASSERT_EQ(32, event.length()); - } -} - -TEST(TextEditingEvent, AsSDLEvent) -{ - const cen::text_editing_event event; - const auto sdl = cen::as_sdl_event(event); - - ASSERT_EQ(sdl.edit.type, cen::to_underlying(event.type())); - ASSERT_EQ(sdl.edit.timestamp, event.timestamp().count()); -} diff --git a/test/unit-tests/event/text/text_editing_ext_event_test.cpp b/test/unit-tests/event/text/text_editing_ext_event_test.cpp deleted file mode 100644 index 1cfbab642..000000000 --- a/test/unit-tests/event/text/text_editing_ext_event_test.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/misc_events.hpp" - -#if SDL_VERSION_ATLEAST(2, 0, 22) - -TEST(TextEditingExtEvent, Defaults) -{ - cen::text_editing_ext_event event; - ASSERT_EQ(cen::event_type::text_editing_ext, event.type()); -} - -TEST(TextEditingEvent, SetStart) -{ - cen::text_editing_event event; - - event.set_start(42); - ASSERT_EQ(42, event.start()); -} - -TEST(TextEditingEvent, SetLength) -{ - cen::text_editing_event event; - - event.set_length(18); - ASSERT_EQ(18, event.length()); -} - -TEST(TextEditingEvent, SetWindowId) -{ - cen::text_editing_event event; - - const Uint32 id = 2; - event.set_window_id(id); - - ASSERT_EQ(id, event.window_id()); -} - -TEST(TextEditingExtEvent, AsSDLEvent) -{ - const cen::text_editing_ext_event event; - const auto sdl = cen::as_sdl_event(event); - - ASSERT_EQ(sdl.edit.type, cen::to_underlying(event.type())); - ASSERT_EQ(sdl.edit.timestamp, event.timestamp().count()); -} - -#endif // SDL_VERSION_ATLEAST(2, 0, 22) diff --git a/test/unit-tests/event/text/text_input_event_test.cpp b/test/unit-tests/event/text/text_input_event_test.cpp deleted file mode 100644 index 94d84c809..000000000 --- a/test/unit-tests/event/text/text_input_event_test.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/misc_events.hpp" - -TEST(TextInputEvent, Defaults) -{ - cen::text_input_event event; - ASSERT_EQ(cen::event_type::text_input, event.type()); -} - -TEST(TextInputEvent, SetWindowId) -{ - cen::text_input_event event; - - constexpr Uint32 id = 23; - event.set_window_id(id); - - ASSERT_EQ(id, event.window_id()); -} - -TEST(TextInputEvent, WindowId) -{ - SDL_TextInputEvent sdl {}; - sdl.type = SDL_TEXTINPUT; - sdl.windowID = 8; - - const cen::text_input_event event {sdl}; - ASSERT_EQ(sdl.windowID, event.window_id()); -} - -TEST(TextInputEvent, TextUtf8) -{ - const SDL_TextInputEvent sdl {SDL_TEXTINPUT, 1, 1, "hello"}; - const cen::text_input_event event {sdl}; - ASSERT_EQ("hello", event.text_utf8()); -} - -TEST(TextInputEvent, AsSDLEvent) -{ - const cen::text_input_event event; - const auto sdl = cen::as_sdl_event(event); - - ASSERT_EQ(sdl.text.type, cen::to_underlying(event.type())); - ASSERT_EQ(sdl.text.timestamp, event.timestamp().count()); -} diff --git a/test/unit-tests/event/window/window_event_id_test.cpp b/test/unit-tests/event/window/window_event_id_test.cpp deleted file mode 100644 index 7762763d5..000000000 --- a/test/unit-tests/event/window/window_event_id_test.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // cout - -#include "centurion/events/window_events.hpp" - -using id = cen::window_event_id; - -TEST(WindowEventID, Values) -{ - ASSERT_EQ(SDL_WINDOWEVENT_NONE, to_underlying(id::none)); - ASSERT_EQ(SDL_WINDOWEVENT_SHOWN, to_underlying(id::shown)); - ASSERT_EQ(SDL_WINDOWEVENT_HIDDEN, to_underlying(id::hidden)); - ASSERT_EQ(SDL_WINDOWEVENT_EXPOSED, to_underlying(id::exposed)); - ASSERT_EQ(SDL_WINDOWEVENT_MOVED, to_underlying(id::moved)); - ASSERT_EQ(SDL_WINDOWEVENT_RESIZED, to_underlying(id::resized)); - ASSERT_EQ(SDL_WINDOWEVENT_SIZE_CHANGED, to_underlying(id::size_changed)); - ASSERT_EQ(SDL_WINDOWEVENT_MINIMIZED, to_underlying(id::minimized)); - ASSERT_EQ(SDL_WINDOWEVENT_MAXIMIZED, to_underlying(id::maximized)); - ASSERT_EQ(SDL_WINDOWEVENT_RESTORED, to_underlying(id::restored)); - ASSERT_EQ(SDL_WINDOWEVENT_ENTER, to_underlying(id::enter)); - ASSERT_EQ(SDL_WINDOWEVENT_LEAVE, to_underlying(id::leave)); - ASSERT_EQ(SDL_WINDOWEVENT_FOCUS_GAINED, to_underlying(id::focus_gained)); - ASSERT_EQ(SDL_WINDOWEVENT_FOCUS_LOST, to_underlying(id::focus_lost)); - ASSERT_EQ(SDL_WINDOWEVENT_CLOSE, to_underlying(id::close)); - ASSERT_EQ(SDL_WINDOWEVENT_TAKE_FOCUS, to_underlying(id::take_focus)); - ASSERT_EQ(SDL_WINDOWEVENT_HIT_TEST, to_underlying(id::hit_test)); - -#if SDL_VERSION_ATLEAST(2, 0, 18) - ASSERT_EQ(SDL_WINDOWEVENT_DISPLAY_CHANGED, to_underlying(id::display_changed)); - ASSERT_EQ(SDL_WINDOWEVENT_ICCPROF_CHANGED, to_underlying(id::icc_profile_changed)); -#endif // SDL_VERSION_ATLEAST(2, 0, 18) -} - -TEST(WindowEventID, ToString) -{ - ASSERT_THROW(to_string(static_cast(100)), cen::exception); - - ASSERT_EQ("none", to_string(id::none)); - ASSERT_EQ("shown", to_string(id::shown)); - ASSERT_EQ("hidden", to_string(id::hidden)); - ASSERT_EQ("exposed", to_string(id::exposed)); - ASSERT_EQ("moved", to_string(id::moved)); - ASSERT_EQ("resized", to_string(id::resized)); - ASSERT_EQ("size_changed", to_string(id::size_changed)); - ASSERT_EQ("minimized", to_string(id::minimized)); - ASSERT_EQ("maximized", to_string(id::maximized)); - ASSERT_EQ("restored", to_string(id::restored)); - ASSERT_EQ("enter", to_string(id::enter)); - ASSERT_EQ("leave", to_string(id::leave)); - ASSERT_EQ("focus_gained", to_string(id::focus_gained)); - ASSERT_EQ("focus_lost", to_string(id::focus_lost)); - ASSERT_EQ("close", to_string(id::close)); - ASSERT_EQ("take_focus", to_string(id::take_focus)); - ASSERT_EQ("hit_test", to_string(id::hit_test)); - -#if SDL_VERSION_ATLEAST(2, 0, 18) - ASSERT_EQ("display_changed", to_string(id::display_changed)); - ASSERT_EQ("icc_profile_changed", to_string(id::icc_profile_changed)); -#endif // SDL_VERSION_ATLEAST(2, 0, 18) - - std::cout << "window_event_id::resized == " << id::resized << '\n'; -} diff --git a/test/unit-tests/event/window/window_event_test.cpp b/test/unit-tests/event/window/window_event_test.cpp deleted file mode 100644 index 4a8faf710..000000000 --- a/test/unit-tests/event/window/window_event_test.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/events/window_events.hpp" - -TEST(window_event, Defaults) -{ - const cen::window_event event; - ASSERT_EQ(cen::event_type::window, event.type()); - ASSERT_EQ(cen::window_event_id::none, event.event_id()); -} - -TEST(WindowEvent, SetEventID) -{ - cen::window_event event; - - event.set_event_id(cen::window_event_id::focus_gained); - ASSERT_EQ(cen::window_event_id::focus_gained, event.event_id()); -} - -TEST(WindowEvent, SetData1) -{ - cen::window_event event; - event.set_event_id(cen::window_event_id::resized); - - const cen::int32 data = 75; - event.set_data1(data); - - ASSERT_EQ(cen::window_event_id::resized, event.event_id()); - ASSERT_EQ(data, event.data1()); - ASSERT_EQ(0, event.data2()); -} - -TEST(WindowEvent, SetData2) -{ - cen::window_event event; - event.set_event_id(cen::window_event_id::resized); - - const cen::int32 data = 54; - event.set_data2(data); - - ASSERT_EQ(cen::window_event_id::resized, event.event_id()); - ASSERT_EQ(0, event.data1()); - ASSERT_EQ(data, event.data2()); -} - -TEST(WindowEvent, AsSDLEvent) -{ - const cen::window_event event; - const auto underlying = cen::as_sdl_event(event); - - ASSERT_EQ(underlying.window.type, to_underlying(event.type())); - ASSERT_EQ(underlying.window.timestamp, event.timestamp().count()); -} diff --git a/test/unit-tests/filesystem/base_path_test.cpp b/test/unit-tests/filesystem/base_path_test.cpp deleted file mode 100644 index 4ab91d284..000000000 --- a/test/unit-tests/filesystem/base_path_test.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/io/paths.hpp" - -TEST(BasePath, NoExceptions) -{ - ASSERT_NO_THROW(cen::base_path()); // NOLINT -} diff --git a/test/unit-tests/filesystem/file_mode_test.cpp b/test/unit-tests/filesystem/file_mode_test.cpp deleted file mode 100644 index ac9925fe5..000000000 --- a/test/unit-tests/filesystem/file_mode_test.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "centurion/io/file_mode.hpp" - -#include - -#include // cout - -TEST(FileMode, ToString) -{ - ASSERT_EQ("r", to_string(cen::file_mode::r)); - ASSERT_EQ("rb", to_string(cen::file_mode::rb)); - - ASSERT_EQ("w", to_string(cen::file_mode::w)); - ASSERT_EQ("wb", to_string(cen::file_mode::wb)); - - ASSERT_EQ("a", to_string(cen::file_mode::a)); - ASSERT_EQ("ab", to_string(cen::file_mode::ab)); - - ASSERT_EQ("rx", to_string(cen::file_mode::rx)); - ASSERT_EQ("rbx", to_string(cen::file_mode::rbx)); - - ASSERT_EQ("wx", to_string(cen::file_mode::wx)); - ASSERT_EQ("wbx", to_string(cen::file_mode::wbx)); - - ASSERT_EQ("ax", to_string(cen::file_mode::ax)); - ASSERT_EQ("abx", to_string(cen::file_mode::abx)); - - std::cout << "file_mode::rb == " << cen::file_mode::rb << '\n'; -} \ No newline at end of file diff --git a/test/unit-tests/filesystem/file_test.cpp b/test/unit-tests/filesystem/file_test.cpp deleted file mode 100644 index 241bb6933..000000000 --- a/test/unit-tests/filesystem/file_test.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "centurion/io/file.hpp" - -#include - -#include // array -#include // size_t -#include // vector - -#include "centurion/io/paths.hpp" - -class FileTest : public testing::Test { - public: - inline static const auto prefs = cen::preferred_path("centurion", "tests").copy(); - inline static const auto path = prefs + "file"; -}; - -TEST_F(FileTest, PointerConstructor) -{ - ASSERT_NO_THROW(cen::file {nullptr}); -} - -TEST_F(FileTest, WriteAndRead) -{ - { - // Create a file which we will write some data to - cen::file file {path, cen::file_mode::wbx}; - ASSERT_TRUE(file); - - ASSERT_EQ(4, file.write("abc")); - - int buffer[] = {1, 2, 3}; - ASSERT_EQ(3, file.write(buffer)); // Implicit capture of buffer size - ASSERT_EQ(1, file.write(buffer, 1)); - - std::array array {4, 5, 6}; - ASSERT_EQ(3, file.write(array)); - - std::vector vector {7, 8, 9}; - ASSERT_EQ(3, file.write(vector)); - - ASSERT_TRUE(file.write_byte(42u)); - - ASSERT_TRUE(file.write_native_as_big_endian(Uint16 {12})); - ASSERT_TRUE(file.write_native_as_big_endian(Uint32 {34})); - ASSERT_TRUE(file.write_native_as_big_endian(Uint64 {56})); - - ASSERT_TRUE(file.write_native_as_little_endian(Uint16 {78})); - ASSERT_TRUE(file.write_native_as_little_endian(Uint32 {90})); - ASSERT_TRUE(file.write_native_as_little_endian(Uint64 {27})); - } - - { - cen::file file {path, cen::file_mode::rb}; - ASSERT_TRUE(file); - - char str[] = "___"; - ASSERT_EQ(4, file.read_to(str)); - - int buffer[] = {0, 0, 0}; - ASSERT_EQ(3, file.read_to(buffer)); - - const auto i = file.read(); - - std::array array {0, 0, 0}; - ASSERT_EQ(3, file.read_to(array)); - - std::vector vector {0, 0, 0}; - ASSERT_EQ(3, file.read_to(vector)); - - ASSERT_STREQ("abc", str); - - ASSERT_EQ(1, buffer[0]); - ASSERT_EQ(2, buffer[1]); - ASSERT_EQ(3, buffer[2]); - - ASSERT_EQ(1, i); - - ASSERT_EQ(4, array.at(0)); - ASSERT_EQ(5, array.at(1)); - ASSERT_EQ(6, array.at(2)); - - ASSERT_EQ(7, vector.at(0)); - ASSERT_EQ(8, vector.at(1)); - ASSERT_EQ(9, vector.at(2)); - - ASSERT_EQ(42u, file.read_byte()); - - ASSERT_EQ(12u, file.read_big_endian_u16()); - ASSERT_EQ(34u, file.read_big_endian_u32()); - ASSERT_EQ(56u, file.read_big_endian_u64()); - - ASSERT_EQ(78u, file.read_little_endian_u16()); - ASSERT_EQ(90u, file.read_little_endian_u32()); - ASSERT_EQ(27u, file.read_little_endian_u64()); - } -} - -TEST_F(FileTest, Queries) -{ - const cen::file file {path, cen::file_mode::rb}; - ASSERT_EQ(SDL_RWtell(file.data()), file.offset()); - ASSERT_EQ(static_cast(SDL_RWsize(file.data())), file.size()); - ASSERT_EQ(file.data()->type, cen::to_underlying(file.type())); -} - -TEST_F(FileTest, IsPNG) -{ - cen::file file {"resources/panda.png", cen::file_mode::r}; - ASSERT_TRUE(file); - - ASSERT_TRUE(file.is_png()); -} diff --git a/test/unit-tests/filesystem/file_type_test.cpp b/test/unit-tests/filesystem/file_type_test.cpp deleted file mode 100644 index d5f76fbcd..000000000 --- a/test/unit-tests/filesystem/file_type_test.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "centurion/io/file_type.hpp" - -#include - -#include // cout - -#include "centurion/common/utils.hpp" - -TEST(FileType, Values) -{ - ASSERT_EQ(SDL_RWOPS_UNKNOWN, to_underlying(cen::file_type::unknown)); - ASSERT_EQ(SDL_RWOPS_WINFILE, to_underlying(cen::file_type::win)); - ASSERT_EQ(SDL_RWOPS_STDFILE, to_underlying(cen::file_type::std)); - ASSERT_EQ(SDL_RWOPS_JNIFILE, to_underlying(cen::file_type::jni)); - ASSERT_EQ(SDL_RWOPS_MEMORY, to_underlying(cen::file_type::memory)); - ASSERT_EQ(SDL_RWOPS_MEMORY_RO, to_underlying(cen::file_type::memory_ro)); -} - -TEST(FileType, ToString) -{ - ASSERT_EQ("unknown", to_string(cen::file_type::unknown)); - ASSERT_EQ("win", to_string(cen::file_type::win)); - ASSERT_EQ("std", to_string(cen::file_type::std)); - ASSERT_EQ("jni", to_string(cen::file_type::jni)); - ASSERT_EQ("memory", to_string(cen::file_type::memory)); - ASSERT_EQ("memory_ro", to_string(cen::file_type::memory_ro)); - - std::cout << "file_type::std == " << cen::file_type::std << '\n'; -} \ No newline at end of file diff --git a/test/unit-tests/filesystem/preferred_path_test.cpp b/test/unit-tests/filesystem/preferred_path_test.cpp deleted file mode 100644 index 4796a032b..000000000 --- a/test/unit-tests/filesystem/preferred_path_test.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include "centurion/io/paths.hpp" - -TEST(PreferredPath, NoExceptions) -{ - using namespace std::string_literals; - ASSERT_NO_THROW(cen::preferred_path("centurion"s, "tests"s)); -} diff --git a/test/unit-tests/filesystem/seek_mode_test.cpp b/test/unit-tests/filesystem/seek_mode_test.cpp deleted file mode 100644 index 496453128..000000000 --- a/test/unit-tests/filesystem/seek_mode_test.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "centurion/io/seek_mode.hpp" - -#include - -#include // cout - -#include "centurion/common/utils.hpp" - -TEST(SeekMode, Values) -{ - ASSERT_EQ(RW_SEEK_SET, to_underlying(cen::seek_mode::from_beginning)); - ASSERT_EQ(RW_SEEK_CUR, to_underlying(cen::seek_mode::relative_to_current)); - ASSERT_EQ(RW_SEEK_END, to_underlying(cen::seek_mode::relative_to_end)); -} - -TEST(SeekMode, ToString) -{ - ASSERT_EQ("from_beginning", to_string(cen::seek_mode::from_beginning)); - ASSERT_EQ("relative_to_current", to_string(cen::seek_mode::relative_to_current)); - ASSERT_EQ("relative_to_end", to_string(cen::seek_mode::relative_to_end)); - - std::cout << "seek_mode::from_beginning == " << cen::seek_mode::from_beginning << '\n'; -} diff --git a/test/unit-tests/input/button_state_test.cpp b/test/unit-tests/input/button_state_test.cpp deleted file mode 100644 index 8ffc3adab..000000000 --- a/test/unit-tests/input/button_state_test.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // cout - -#include "centurion/input.hpp" - -TEST(ButtonState, Values) -{ - ASSERT_EQ(SDL_RELEASED, to_underlying(cen::button_state::released)); - ASSERT_EQ(SDL_PRESSED, to_underlying(cen::button_state::pressed)); -} - -TEST(ButtonState, ToString) -{ - ASSERT_THROW(to_string(static_cast(3)), cen::exception); - - ASSERT_EQ("released", to_string(cen::button_state::released)); - ASSERT_EQ("pressed", to_string(cen::button_state::pressed)); - - std::cout << "button_state::pressed == " << cen::button_state::pressed << '\n'; -} diff --git a/test/unit-tests/input/controller/controller_axis_test.cpp b/test/unit-tests/input/controller/controller_axis_test.cpp deleted file mode 100644 index 3e8cc958c..000000000 --- a/test/unit-tests/input/controller/controller_axis_test.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // cout - -#include "centurion/input/controller.hpp" - -using axis = cen::controller_axis; - -TEST(ControllerAxis, Values) -{ - ASSERT_EQ(SDL_CONTROLLER_AXIS_INVALID, to_underlying(axis::invalid)); - ASSERT_EQ(SDL_CONTROLLER_AXIS_LEFTX, to_underlying(axis::left_x)); - ASSERT_EQ(SDL_CONTROLLER_AXIS_LEFTY, to_underlying(axis::left_y)); - ASSERT_EQ(SDL_CONTROLLER_AXIS_RIGHTX, to_underlying(axis::right_x)); - ASSERT_EQ(SDL_CONTROLLER_AXIS_RIGHTY, to_underlying(axis::right_y)); - ASSERT_EQ(SDL_CONTROLLER_AXIS_TRIGGERLEFT, to_underlying(axis::trigger_left)); - ASSERT_EQ(SDL_CONTROLLER_AXIS_TRIGGERRIGHT, to_underlying(axis::trigger_right)); - ASSERT_EQ(SDL_CONTROLLER_AXIS_MAX, to_underlying(axis::max)); -} - -TEST(ControllerAxis, ToString) -{ - ASSERT_THROW(to_string(static_cast(SDL_CONTROLLER_AXIS_MAX + 1)), cen::exception); - - ASSERT_EQ("invalid", to_string(axis::invalid)); - - ASSERT_EQ("left_x", to_string(axis::left_x)); - ASSERT_EQ("left_y", to_string(axis::left_y)); - - ASSERT_EQ("right_x", to_string(axis::right_x)); - ASSERT_EQ("right_y", to_string(axis::right_y)); - - ASSERT_EQ("trigger_left", to_string(axis::trigger_left)); - ASSERT_EQ("trigger_right", to_string(axis::trigger_right)); - - ASSERT_EQ("max", to_string(axis::max)); - - std::cout << "controller_axis::right_x == " << axis::right_x << '\n'; -} diff --git a/test/unit-tests/input/controller/controller_bind_type_test.cpp b/test/unit-tests/input/controller/controller_bind_type_test.cpp deleted file mode 100644 index 7f6a07a67..000000000 --- a/test/unit-tests/input/controller/controller_bind_type_test.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // cout - -#include "centurion/input/controller.hpp" - -using bind_type = cen::controller_bind_type; - -TEST(ControllerBindType, Values) -{ - ASSERT_EQ(SDL_CONTROLLER_BINDTYPE_AXIS, to_underlying(bind_type::axis)); - ASSERT_EQ(SDL_CONTROLLER_BINDTYPE_BUTTON, to_underlying(bind_type::button)); - ASSERT_EQ(SDL_CONTROLLER_BINDTYPE_NONE, to_underlying(bind_type::none)); - ASSERT_EQ(SDL_CONTROLLER_BINDTYPE_HAT, to_underlying(bind_type::hat)); -} - -TEST(ControllerBindType, ToString) -{ - ASSERT_THROW(to_string(static_cast(100)), cen::exception); - - ASSERT_EQ("none", to_string(bind_type::none)); - ASSERT_EQ("button", to_string(bind_type::button)); - ASSERT_EQ("axis", to_string(bind_type::axis)); - ASSERT_EQ("hat", to_string(bind_type::hat)); - - std::cout << "controller_bind_type::button == " << bind_type::button << '\n'; -} diff --git a/test/unit-tests/input/controller/controller_button_test.cpp b/test/unit-tests/input/controller/controller_button_test.cpp deleted file mode 100644 index fcd24cae2..000000000 --- a/test/unit-tests/input/controller/controller_button_test.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * MIT License - * - * Copyright (c) 2019-2023 Albin Johansson - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include - -#include // cout - -#include "centurion/input/controller.hpp" - -using button = cen::controller_button; - -TEST(ControllerButton, Values) -{ - ASSERT_EQ(SDL_CONTROLLER_BUTTON_INVALID, to_underlying(button::invalid)); - - ASSERT_EQ(SDL_CONTROLLER_BUTTON_A, to_underlying(button::a)); - ASSERT_EQ(SDL_CONTROLLER_BUTTON_B, to_underlying(button::b)); - ASSERT_EQ(SDL_CONTROLLER_BUTTON_X, to_underlying(button::x)); - ASSERT_EQ(SDL_CONTROLLER_BUTTON_Y, to_underlying(button::y)); - - ASSERT_EQ(SDL_CONTROLLER_BUTTON_BACK, to_underlying(button::back)); - ASSERT_EQ(SDL_CONTROLLER_BUTTON_GUIDE, to_underlying(button::guide)); - ASSERT_EQ(SDL_CONTROLLER_BUTTON_START, to_underlying(button::start)); - - ASSERT_EQ(SDL_CONTROLLER_BUTTON_LEFTSTICK, to_underlying(button::left_stick)); - ASSERT_EQ(SDL_CONTROLLER_BUTTON_RIGHTSTICK, to_underlying(button::right_stick)); - ASSERT_EQ(SDL_CONTROLLER_BUTTON_LEFTSHOULDER, to_underlying(button::left_shoulder)); - ASSERT_EQ(SDL_CONTROLLER_BUTTON_RIGHTSHOULDER, to_underlying(button::right_shoulder)); - - ASSERT_EQ(SDL_CONTROLLER_BUTTON_DPAD_UP, to_underlying(button::dpad_up)); - ASSERT_EQ(SDL_CONTROLLER_BUTTON_DPAD_DOWN, to_underlying(button::dpad_down)); - ASSERT_EQ(SDL_CONTROLLER_BUTTON_DPAD_RIGHT, to_underlying(button::dpad_right)); - ASSERT_EQ(SDL_CONTROLLER_BUTTON_DPAD_LEFT, to_underlying(button::dpad_left)); - ASSERT_EQ(SDL_CONTROLLER_BUTTON_MAX, to_underlying(button::max)); - -#if SDL_VERSION_ATLEAST(2, 0, 14) - ASSERT_EQ(SDL_CONTROLLER_BUTTON_MISC1, to_underlying(button::misc1)); - ASSERT_EQ(SDL_CONTROLLER_BUTTON_PADDLE1, to_underlying(button::paddle1)); - ASSERT_EQ(SDL_CONTROLLER_BUTTON_PADDLE2, to_underlying(button::paddle2)); - ASSERT_EQ(SDL_CONTROLLER_BUTTON_PADDLE3, to_underlying(button::paddle3)); - ASSERT_EQ(SDL_CONTROLLER_BUTTON_PADDLE4, to_underlying(button::paddle4)); - ASSERT_EQ(SDL_CONTROLLER_BUTTON_TOUCHPAD, to_underlying(button::touchpad)); -#endif // SDL_VERSION_ATLEAST(2, 0, 14) -} - -TEST(ControllerButton, ToString) -{ - ASSERT_THROW(to_string(static_cast