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
32TEST_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
39TEST_CASE("DeviceConfiguration::serialize") {
40 DeviceConfiguration configuration("12345", "My Psion");
41 CHECK(configuration.serialize() == "id = 12345\r\nname = My Psion\r\n");
42}
43
44TEST_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}
Class for managing and serializing device details.
static std::unique_ptr< DeviceConfiguration > deserialize(const std::string &contents)
std::string serialize() const
std::string id() const
std::string name() const
#define SUBCASE(name)
Definition: doctest.h:2946
#define CHECK(...)
Definition: doctest.h:2970
#define TEST_CASE(name)
Definition: doctest.h:2937
std::string uuid4()
Definition: uuid.cc:30