summaryrefslogtreecommitdiff
path: root/test/pointerlist_test.cc
blob: 329e3199e85fd3a1f3966cceab351491f4193131 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// -*- c++ -*-
// Distributed under the BSD 2-Clause License.
// See accompanying file LICENSE for details.
#include <uunit.h>

#include "pointerlist.h"

class PointerListTest
	: public uUnit
{
public:
	PointerListTest()
	{
		uTEST(PointerListTest::test_zom_push);
		uTEST(PointerListTest::test_zom_from_args);
	}

	void test_zom_push()
	{
		using namespace std::string_literals;

		{ // Zero
			PointerList args;
			uASSERT_EQUAL(0u, args.size());
			auto [argc, argv] = args.get();
			uASSERT_EQUAL(0, argc);
			uASSERT_EQUAL(nullptr, argv);
		}

		{ // One
			PointerList args;
			args.push_back("hello");
			uASSERT_EQUAL(1u, args.size());
			auto [argc, argv] = args.get();
			uASSERT_EQUAL(1, argc);
			uASSERT_EQUAL("hello"s, std::string(argv[0]));
		}

		{ // Many
			PointerList args;
			args.push_back("hello");
			args.push_back("dear");
			args.push_back("world");
			uASSERT_EQUAL(3u, args.size());
			auto [argc, argv] = args.get();
			uASSERT_EQUAL(3, argc);
			uASSERT_EQUAL("hello"s, std::string(argv[0]));
			uASSERT_EQUAL("dear"s, std::string(argv[1]));
			uASSERT_EQUAL("world"s, std::string(argv[2]));
		}
	}

	void test_zom_from_args()
	{
		using namespace std::string_literals;

		{ // Zero
			PointerList args(0, nullptr);
			uASSERT_EQUAL(0u, args.size());
			auto [argc, argv] = args.get();
			uASSERT_EQUAL(0, argc);
			uASSERT_EQUAL(nullptr, argv);
		}

		{ // One
			int _argc{1};
			const char* _argv[] = { "hello" };
			PointerList args(_argc, _argv);
			uASSERT_EQUAL(1u, args.size());
			auto [argc, argv] = args.get();
			uASSERT_EQUAL(1, argc);
			uASSERT_EQUAL("hello"s, std::string(argv[0]));
		}

		{ // Many
			int _argc{3};
			const char* _argv[] = { "hello", "dear", "world" };
			PointerList args(_argc, _argv);
			uASSERT_EQUAL(3u, args.size());
			auto [argc, argv] = args.get();
			uASSERT_EQUAL(3, argc);
			uASSERT_EQUAL("hello"s, std::string(argv[0]));
			uASSERT_EQUAL("dear"s, std::string(argv[1]));
			uASSERT_EQUAL("world"s, std::string(argv[2]));
		}
	}
};

// Registers the fixture into the 'registry'
static PointerListTest test;