plptools
Loading...
Searching...
No Matches
deviceconfigurationtests.cc
Go to the documentation of this file.
1
/*
2
* This file is part of plptools.
3
*
4
* Copyright (c) 2026 Jason Morley <hello@jbmorley.co.uk>
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License along
17
* along with this program; if not, see <https://www.gnu.org/licenses/>.
18
*
19
*/
20
#include "config.h"
21
22
#include <iostream>
23
#include <ostream>
24
#include <stdio.h>
25
#include <stdlib.h>
26
27
#include "
doctest.h
"
28
#include "
deviceconfiguration.h
"
29
#include "
pathutils.h
"
30
#include "
uuid.h
"
31
32
TEST_CASE
(
"DeviceConfiguration accessors"
) {
33
std::string
id
=
uuid::uuid4
();
34
DeviceConfiguration
configuration(
id
,
"My Psion"
);
35
CHECK
(configuration.
id
() ==
id
);
36
CHECK
(configuration.
name
() ==
"My Psion"
);
37
}
38
39
TEST_CASE
(
"DeviceConfiguration::serialize"
) {
40
DeviceConfiguration
configuration(
"12345"
,
"My Psion"
);
41
CHECK
(configuration.
serialize
() ==
"id = 12345\r\nname = My Psion\r\n"
);
42
}
43
44
TEST_CASE
(
"DeviceConfiguration::deserialize"
) {
45
46
SUBCASE
(
"non-empty name"
) {
47
DeviceConfiguration
configuration(
"123456"
,
"My Psion"
);
48
std::string stringRepresentation = configuration.
serialize
();
49
auto
result =
DeviceConfiguration::deserialize
(stringRepresentation);
50
CHECK
(result->id() ==
"123456"
);
51
CHECK
(result->name() ==
"My Psion"
);
52
}
53
54
SUBCASE
(
"empty name"
) {
55
DeviceConfiguration
configuration(
"123456"
,
""
);
56
std::string stringRepresentation = configuration.
serialize
();
57
auto
result =
DeviceConfiguration::deserialize
(stringRepresentation);
58
CHECK
(result->id() ==
"123456"
);
59
CHECK
(result->name() ==
""
);
60
}
61
62
SUBCASE
(
"Reconnect configuration"
) {
63
std::string configuration =R
"(id = C35B9D58-9865-462F-BC39-52A5DFAB3E4D
64
name = Series 3a
65
)";
66
auto
result =
DeviceConfiguration::deserialize
(configuration);
67
CHECK
(result->id() ==
"C35B9D58-9865-462F-BC39-52A5DFAB3E4D"
);
68
CHECK
(result->name() ==
"Series 3a"
);
69
}
70
}
DeviceConfiguration
Class for managing and serializing device details.
Definition
deviceconfiguration.h:34
DeviceConfiguration::deserialize
static std::unique_ptr< DeviceConfiguration > deserialize(const std::string &contents)
Definition
deviceconfiguration.cc:31
DeviceConfiguration::serialize
std::string serialize() const
Definition
deviceconfiguration.cc:52
DeviceConfiguration::id
std::string id() const
Definition
deviceconfiguration.h:43
DeviceConfiguration::name
std::string name() const
Definition
deviceconfiguration.h:47
deviceconfiguration.h
doctest.h
SUBCASE
#define SUBCASE(name)
Definition
doctest.h:2946
CHECK
#define CHECK(...)
Definition
doctest.h:2970
TEST_CASE
#define TEST_CASE(name)
Definition
doctest.h:2937
uuid::uuid4
std::string uuid4()
Definition
uuid.cc:30
pathutils.h
uuid.h
tests
deviceconfigurationtests.cc
Generated by
1.12.0