feat: extract test code

This commit is contained in:
Michael Mandl 2023-10-18 19:49:49 +02:00
parent 2799111d21
commit 1c9b7cb3f4
Signed by: mandlm
GPG key ID: 4AA25D647AA54CC7
4 changed files with 37 additions and 23 deletions

View file

@ -12,7 +12,7 @@ include(ExportCompileCommands)
configure_file("${PROJECT_SOURCE_DIR}/include/version.h.in" configure_file("${PROJECT_SOURCE_DIR}/include/version.h.in"
"${PROJECT_BINARY_DIR}/include/version.h") "${PROJECT_BINARY_DIR}/include/version.h")
add_executable(hello src/main.cpp) add_executable(hello src/main.cpp src/null.cpp)
target_compile_features(hello PUBLIC cxx_std_20) target_compile_features(hello PUBLIC cxx_std_20)
target_include_directories(hello PRIVATE "${PROJECT_BINARY_DIR}/include") target_include_directories(hello PRIVATE "${PROJECT_BINARY_DIR}/include")

View file

@ -1,36 +1,16 @@
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <type_traits>
#include "version.h" #include "version.h"
void call_test(char *) { std::cout << "call_test(char *) called" << std::endl; } #include "null.h"
void call_test(int) { std::cout << "call_test(int) called" << std::endl; }
int main(int argc, char **argv) { int main(int argc, char **argv) {
std::cout << "Running " << PROJECT_NAME << ", version " << VERSION << "\n" std::cout << "Running " << PROJECT_NAME << ", version " << VERSION << "\n"
<< std::endl; << std::endl;
if (std::is_same<decltype(NULL), decltype(0)>::value) { null::test();
std::cout << "NULL == 0" << std::endl;
}
if (std::is_same<decltype(NULL), decltype((void *)0)>::value) {
std::cout << "NULL == (void *)0" << std::endl;
}
if (std::is_same<decltype(NULL), decltype(__null)>::value) {
std::cout << "NULL == __null" << std::endl;
}
if (std::is_same<decltype(NULL), std::nullptr_t>::value) {
std::cout << "NULL == nullptr" << std::endl;
}
call_test(0);
call_test(nullptr);
std::cout << "\nExiting" << std::endl; std::cout << "\nExiting" << std::endl;

29
src/null.cpp Normal file
View file

@ -0,0 +1,29 @@
#include <iostream>
#include <type_traits>
#include "null.h"
void call_test(char *) { std::cout << "call_test(char *) called" << std::endl; }
void call_test(int) { std::cout << "call_test(int) called" << std::endl; }
void null::test() {
if (std::is_same<decltype(NULL), decltype(0)>::value) {
std::cout << "NULL == 0" << std::endl;
}
if (std::is_same<decltype(NULL), decltype((void *)0)>::value) {
std::cout << "NULL == (void *)0" << std::endl;
}
if (std::is_same<decltype(NULL), decltype(__null)>::value) {
std::cout << "NULL == __null" << std::endl;
}
if (std::is_same<decltype(NULL), std::nullptr_t>::value) {
std::cout << "NULL == nullptr" << std::endl;
}
call_test(0);
call_test(nullptr);
}

5
src/null.h Normal file
View file

@ -0,0 +1,5 @@
#pragma once
namespace null {
void test();
};