Update test helpers

This commit is contained in:
ado 2023-07-29 13:56:00 +02:00
parent 5d6c2c4af5
commit a98742945b
2 changed files with 39 additions and 62 deletions

View File

@ -1,7 +1,5 @@
#pragma once #pragma once
#define _CRT_SECURE_NO_WARNINGS
#include "common.hpp" #include "common.hpp"
#include "converter.hpp" #include "converter.hpp"
#include "extract.hpp" #include "extract.hpp"

View File

@ -1,9 +1,6 @@
#pragma once #pragma once
#define _CRT_SECURE_NO_WARNINGS #include <string>
#include <cstdlib>
#include <cstring>
#ifdef CMAKE_GITHUB_CI #ifdef CMAKE_GITHUB_CI
#include <doctest/doctest.h> #include <doctest/doctest.h>
@ -12,40 +9,22 @@
#endif #endif
struct buffer { struct buffer {
char* data_{nullptr}; std::string data_;
char* operator()(const char* data) { char *operator()(const std::string &data) {
if (data_) { data_ = data;
delete[] data_; return data_.data();
}
data_ = new char[strlen(data) + 1];
strcpy(data_, data);
return data_;
} }
char* append(const char* data) { char *append(const std::string &data) {
if (data_) { data_ += data;
char* new_data_ = new char[strlen(data_) + strlen(data) + 1]; return data_.data();
strcpy(new_data_, data_);
strcat(new_data_, data);
delete[] data_;
data_ = new_data_;
return data_;
} else {
return operator()(data);
}
} }
char* append_overwrite_last(const char* data, size_t size) { char *append_overwrite_last(const std::string &data, size_t size) {
data_[strlen(data_) - size] = '\0'; data_.resize(data_.size() - size);
return append(data); return append(data);
} }
~buffer() {
if (data_) {
delete[] data_;
}
}
}; };
[[maybe_unused]] inline buffer buff; [[maybe_unused]] inline buffer buff;