Skip to content

Commit bf100f8

Browse files
committed
Added some test files
1 parent 06dfe1e commit bf100f8

File tree

7 files changed

+77
-50
lines changed

7 files changed

+77
-50
lines changed

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ cmake_minimum_required(VERSION 3.28)
22
project(sync_send)
33

44
set (CMAKE_CXX_STANDARD 23)
5-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-address-use-after-return=runtime")
5+
#set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize-address-use-after-return=runtime")
66

77
enable_testing()
8-
add_subdirectory(tests)
8+
add_subdirectory(tests)
9+
add_subdirectory(include/scl)

include/scl/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
set(CMAKE_CXX_STANDARD 23)
2+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
3+
4+
include(../../cmake/icm_build_failure_testing.cmake)
5+
include(../../cmake/icm_testing.cmake)
6+
7+
# Global include for icm based tests
8+
include_directories("../include")
9+
10+
file(GLOB_RECURSE pass_files LIST_DIRECTORIES false "${CMAKE_CURRENT_SOURCE_DIR}" *.test.cpp)
11+
message(pass_files: ${pass_files})
12+
13+
foreach(pass_file ${pass_files})
14+
get_filename_component(name_without_extension "${pass_file}" NAME_WE)
15+
icm_add_test(
16+
NAME ${name_without_extension}
17+
SOURCES ${pass_file}
18+
)
19+
endforeach()
Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#pragma once
77

8-
#include <type_traits>
98
#include "sync_send.h"
109

1110

@@ -44,48 +43,3 @@ struct is_send<synchronized_value<T>&> : std::true_type {};
4443

4544
template<typename T>
4645
struct is_sync<synchronized_value<T>> : std::true_type {};
47-
48-
49-
#include <string>
50-
#include <cassert>
51-
52-
53-
synchronized_value<std::string> s;
54-
55-
std::string read_value() {
56-
return apply([](auto &x) { return x; }, s);
57-
}
58-
59-
void set_value(std::string const &new_val) {
60-
apply([&](auto &x) { x = new_val; }, s);
61-
}
62-
63-
void test_single() {
64-
set_value("new value");
65-
assert(read_value() == "new value");
66-
}
67-
68-
void test_multi() {
69-
synchronized_value<int> a(1), b(2), c(3);
70-
int sum = apply([](auto &...ints) { return (ints++ + ...); }, a, b, c);
71-
assert(sum == 6);
72-
auto get = [](int &i) { return i; };
73-
assert(apply(get, a) == 2);
74-
assert(apply(get, b) == 3);
75-
assert(apply(get, c) == 4);
76-
}
77-
78-
#include <string>
79-
80-
struct person
81-
{
82-
std::string get_name() const;
83-
void set_name (std::string);
84-
85-
std::string name;
86-
};
87-
88-
template<>
89-
struct is_sync<person> : std::true_type {};
90-
91-
static_assert(is_send_v<person>);
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#include <string>
2+
#include <cassert>
3+
#include "synchronized_value.h"
4+
5+
synchronized_value<std::string> s;
6+
7+
std::string read_value() {
8+
return apply([](auto &x) { return x; }, s);
9+
}
10+
11+
void set_value(std::string const &new_val) {
12+
apply([&](auto &x) { x = new_val; }, s);
13+
}
14+
15+
void test_single() {
16+
set_value("new value");
17+
assert(read_value() == "new value");
18+
}
19+
20+
void test_multi() {
21+
synchronized_value<int> a(1), b(2), c(3);
22+
int sum = apply([](auto &...ints) { return (ints++ + ...); }, a, b, c);
23+
assert(sum == 6);
24+
auto get = [](int &i) { return i; };
25+
assert(apply(get, a) == 2);
26+
assert(apply(get, b) == 3);
27+
assert(apply(get, c) == 4);
28+
}
29+
30+
31+
struct person
32+
{
33+
std::string get_name() const;
34+
void set_name (std::string);
35+
36+
std::string name;
37+
};
38+
39+
template<>
40+
struct is_sync<person> : std::true_type {};
41+
42+
static_assert(is_send_v<person>);
43+
44+
int main()
45+
{
46+
test_single();
47+
test_multi();
48+
}

include/scl/type_traits.test.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Created by David Rowland on 17/09/2024.
33
//
44

5-
#include "type_traits.h"
5+
#include "utils/type_traits.h"
66
#include <memory>
77
#include <print>
88
#include <string>
@@ -159,3 +159,8 @@ void test()
159159
static_assert (std::is_class_v<TestCallable>);
160160
}
161161
}
162+
163+
int main()
164+
{
165+
test();
166+
}

tests/pass_shared_syncronised_string.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <print>
44
#include <ranges>
55
#include <scl/safe_thread.h>
6-
#include <scl/syncronized_value.h>
6+
#include <scl/synchronized_value.h>
77

88
using namespace std::literals;
99

0 commit comments

Comments
 (0)