https://github.com/abumq/testx
Extremely simple header-only library to create typesafe test data for your C++ application.
https://github.com/abumq/testx
cpp11 integration-testing testing-tools unit-testing
Last synced: about 1 year ago
JSON representation
Extremely simple header-only library to create typesafe test data for your C++ application.
- Host: GitHub
- URL: https://github.com/abumq/testx
- Owner: abumq
- License: mit
- Created: 2017-08-29T23:58:49.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-06-03T07:28:19.000Z (almost 3 years ago)
- Last Synced: 2025-02-01T10:27:41.244Z (about 1 year ago)
- Topics: cpp11, integration-testing, testing-tools, unit-testing
- Language: C++
- Homepage:
- Size: 20.5 KB
- Stars: 2
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
﷽
# Overview
TestX is extremely simple header to create typesafe test data.
[](https://github.com/abumq/testx/blob/master/LICENSE)
[](https://amrayn.com/donate)
# Usage
You can see practical usage on residue tests [basic](https://github.com/abumq/residue/blob/develop/test/utils-test.h#L65) and [using wrapper](https://github.com/abumq/residue/blob/develop/test/url-test.h)
```c++
#include
using namespace testx;
// c expected
static TestData IsDigitTestData = {
{ '1', true },
{ 'a', false },
}
```
You can use `std::get` to get item without specifying the type
```c++
void testNumber() {
for (auto& item : IsDigitTestData) {
auto c = item.get<0>();
bool expected = item.get<1>();
assert(isdigit(c) == expected));
}
}
```
# Explicit Type
You can specify the test case type and re-use it using wrapper types (`TestDataW` and `TestCaseW`)
```
using URLTestCase = TestCase;
// Notice the TestDataW instead of TestData
// if we used TestData we would do:
// TestData
static TestDataW URLTestData = {
{ "https://192.168.1.100:3322/p1?q=1", "https", "192.168.1.100", "3322", "/p1", "q=1" },
{ "http://192.168.1.19:3000/p2?q2=2", "http", "192.168.1.19", "3000", "/p2", "q2=2" },
{ "HTTP://LOCALHOST:3000/PATH?QUERY1=1&QUERY2=2", "HTTP", "LOCALHOST", "3000", "/PATH", "QUERY1=1&QUERY2=2" },
{ "http://localhost:3000/path?query1=1&query2=2", "http", "localhost", "3000", "/path", "query1=1&query2=2" },
{ "http://localhost", "http", "localhost", "80", "", "" },
{ "http://localhost:3000", "http", "localhost", "3000", "", "" },
{ "http://localhost:3000/", "http", "localhost", "3000", "/", "" },
{ "localhost:3000/", "http", "localhost", "3000", "/", "" },
{ "localhost", "http", "localhost", "80", "", "" },
{ "http://localhost", "http", "localhost", "80", "", "" },
{ "https://localhost", "https", "localhost", "443", "", "" },
{ "localhost/", "http", "localhost", "80", "/", "" },
{ "HTTP://LOCALHOST:3000/PATH?QUERY1=1&QUERY2=2", "HTTP", "LOCALHOST", "3000", "/PATH", "QUERY1=1&QUERY2=2"},
};
void testUrl(const Url& url, const URLTestCase& item) // using URLTestCase that was previously defined
{
ASSERT_EQ(url.protocol(), item.get<1>());
ASSERT_EQ(url.host(), item.get<2>());
ASSERT_EQ(url.port(), item.get<3>());
ASSERT_EQ(url.path(), item.get<4>());
ASSERT_EQ(url.query(), item.get<5>());
ASSERT_TRUE(url.isValid());
}
TEST(UrlTest, TestUrls)
{
for (const auto& item : URLTestData) {
Url url(item.get<0>());
testUrl(url, item);
}
}
```
# License
```
The MIT License (MIT)
Copyright (c) 2017-present @abumq (Majid Q.)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```