NAWA 0.8
Web Application Framework for C++
utils.cpp
Go to the documentation of this file.
1
6/*
7 * Copyright (C) 2019-2021 Tobias Flaig.
8 *
9 * This file is part of nawa.
10 *
11 * nawa is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License,
13 * version 3, as published by the Free Software Foundation.
14 *
15 * nawa is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with nawa. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#include <catch2/catch.hpp>
25#include <nawa/util/utils.h>
26
27using namespace nawa;
28using namespace std;
29
30TEST_CASE("nawa::utils functions", "[unit][utils]") {
31
32 SECTION("Time conversions") {
33 time_t currentTime = time(nullptr);
34 CHECK(utils::readSmtpTime("Thu, 7 Nov 2019 16:29:50 +0100") == 1573140590);
35 CHECK(utils::readHttpTime(utils::makeHttpTime(currentTime)) == currentTime);
36 CHECK(utils::readSmtpTime(utils::makeSmtpTime(currentTime)) == currentTime);
37 }
38
39 SECTION("Path splitting") {
40 string t1 = "p1/p2/p3";
41 string t2 = "/p1/p2/p3";
42 string t3 = "/p1/p2/p3/";
43 string t4 = "/p1/p2/p3?test=/xyz";
44 string t5 = "/p1/p2/p3/?test=/xyz/";
45 auto t1_split = utils::splitPath(t1);
46 CHECK(t1_split == utils::splitPath(t2));
47 CHECK(t1_split == utils::splitPath(t3));
48 CHECK(t1_split == utils::splitPath(t4));
49 CHECK(t1_split == utils::splitPath(t5));
50 }
51}
time_t readSmtpTime(std::string const &smtpTime)
Definition: utils.cpp:388
time_t readHttpTime(std::string const &httpTime)
Definition: utils.cpp:369
std::vector< std::string > splitPath(std::string const &pathString)
Definition: utils.cpp:446
std::string makeHttpTime(time_t time)
Definition: utils.cpp:359
std::string makeSmtpTime(time_t time)
Definition: utils.cpp:378
Definition: AppInit.h:31
TEST_CASE("nawa::utils functions", "[unit][utils]")
Definition: utils.cpp:30
Contains useful functions that improve the readability and facilitate maintenance of the NAWA code.