mirror of
https://github.com/oatpp/oatpp.git
synced 2025-01-18 16:43:57 +08:00
oatpp::Enum. Add description.
This commit is contained in:
parent
9ee3c80626
commit
1d63dd547e
@ -44,7 +44,7 @@ OATPP_MACRO_EXPAND(OATPP_MACRO_MACRO_SELECTOR(MACRO, (__VA_ARGS__)) (NAME, __VA_
|
||||
|
||||
#define OATPP_MACRO_DTO_ENUM_VALUE_1(NAME, VAL) \
|
||||
{ \
|
||||
oatpp::data::mapping::type::EnumValueInfo<EnumType> entry = {EnumType::NAME, index ++, #NAME}; \
|
||||
oatpp::data::mapping::type::EnumValueInfo<EnumType> entry = {EnumType::NAME, index ++, #NAME, nullptr}; \
|
||||
info.byName.insert({#NAME, entry}); \
|
||||
info.byValue.insert({static_cast<v_uint64>(EnumType::NAME), entry}); \
|
||||
info.byIndex.push_back(entry); \
|
||||
@ -52,7 +52,15 @@ OATPP_MACRO_EXPAND(OATPP_MACRO_MACRO_SELECTOR(MACRO, (__VA_ARGS__)) (NAME, __VA_
|
||||
|
||||
#define OATPP_MACRO_DTO_ENUM_VALUE_2(NAME, VAL, QUALIFIER) \
|
||||
{ \
|
||||
oatpp::data::mapping::type::EnumValueInfo<EnumType> entry = {EnumType::NAME, index ++, QUALIFIER}; \
|
||||
oatpp::data::mapping::type::EnumValueInfo<EnumType> entry = {EnumType::NAME, index ++, QUALIFIER, nullptr}; \
|
||||
info.byName.insert({QUALIFIER, entry}); \
|
||||
info.byValue.insert({static_cast<v_uint64>(EnumType::NAME), entry}); \
|
||||
info.byIndex.push_back(entry); \
|
||||
}
|
||||
|
||||
#define OATPP_MACRO_DTO_ENUM_VALUE_3(NAME, VAL, QUALIFIER, DESCRIPTION) \
|
||||
{ \
|
||||
oatpp::data::mapping::type::EnumValueInfo<EnumType> entry = {EnumType::NAME, index ++, QUALIFIER, DESCRIPTION}; \
|
||||
info.byName.insert({QUALIFIER, entry}); \
|
||||
info.byValue.insert({static_cast<v_uint64>(EnumType::NAME), entry}); \
|
||||
info.byIndex.push_back(entry); \
|
||||
|
@ -95,9 +95,10 @@ namespace __class {
|
||||
|
||||
template<typename T>
|
||||
struct EnumValueInfo {
|
||||
const T value;
|
||||
const v_int32 index;
|
||||
const data::share::StringKeyLabel name;
|
||||
T value;
|
||||
v_int32 index;
|
||||
data::share::StringKeyLabel name;
|
||||
data::share::StringKeyLabel description;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
@ -106,7 +107,7 @@ public:
|
||||
const char* nameQualifier = nullptr;
|
||||
std::unordered_map<data::share::StringKeyLabel, EnumValueInfo<T>> byName;
|
||||
std::unordered_map<v_uint64, EnumValueInfo<T>> byValue;
|
||||
std::vector<EnumValueInfo<T>> byIndex;
|
||||
std::vector<const EnumValueInfo<T>> byIndex;
|
||||
};
|
||||
|
||||
template<class T, class Interpreter>
|
||||
@ -286,7 +287,7 @@ public:
|
||||
|
||||
public:
|
||||
|
||||
static EnumValueInfo<T> getEntryByName(const String& name) {
|
||||
static const EnumValueInfo<T>& getEntryByName(const String& name) {
|
||||
auto it = EnumMeta<T>::getInfo()->byName.find(name);
|
||||
if(it != EnumMeta<T>::getInfo()->byName.end()) {
|
||||
return it->second;
|
||||
@ -294,7 +295,7 @@ public:
|
||||
throw std::runtime_error("[oatpp::data::mapping::type::Enum::getEntryByName()]: Error. Entry not found.");
|
||||
}
|
||||
|
||||
static EnumValueInfo<T> getEntryByValue(T value) {
|
||||
static const EnumValueInfo<T>& getEntryByValue(T value) {
|
||||
auto it = EnumMeta<T>::getInfo()->byValue.find(static_cast<v_uint64>(value));
|
||||
if(it != EnumMeta<T>::getInfo()->byValue.end()) {
|
||||
return it->second;
|
||||
@ -302,7 +303,7 @@ public:
|
||||
throw std::runtime_error("[oatpp::data::mapping::type::Enum::getEntryByValue()]: Error. Entry not found.");
|
||||
}
|
||||
|
||||
static EnumValueInfo<T> getEntryByUnderlyingValue(UnderlyingEnumType value) {
|
||||
static const EnumValueInfo<T>& getEntryByUnderlyingValue(UnderlyingEnumType value) {
|
||||
auto it = EnumMeta<T>::getInfo()->byValue.find(static_cast<v_uint64>(value));
|
||||
if(it != EnumMeta<T>::getInfo()->byValue.end()) {
|
||||
return it->second;
|
||||
@ -310,14 +311,14 @@ public:
|
||||
throw std::runtime_error("[oatpp::data::mapping::type::Enum::getEntryByUnderlyingValue()]: Error. Entry not found.");
|
||||
}
|
||||
|
||||
static EnumValueInfo<T> getEntryByIndex(v_int32 index) {
|
||||
static const EnumValueInfo<T>& getEntryByIndex(v_int32 index) {
|
||||
if(index >= 0 && index < EnumMeta<T>::getInfo()->byIndex.size()) {
|
||||
return EnumMeta<T>::getInfo()->byIndex[index];
|
||||
}
|
||||
throw std::runtime_error("[oatpp::data::mapping::type::Enum::getEntryByIndex()]: Error. Entry not found.");
|
||||
}
|
||||
|
||||
static const std::vector<EnumValueInfo<T>>& getEntries() {
|
||||
static const std::vector<const EnumValueInfo<T>>& getEntries() {
|
||||
return EnumMeta<T>::getInfo()->byIndex;
|
||||
}
|
||||
|
||||
|
@ -102,54 +102,54 @@ public:
|
||||
: type::ObjectWrapper<base::StrBuffer, __class::String>(std::forward<String>(other))
|
||||
{}
|
||||
|
||||
String& operator = (std::nullptr_t) {
|
||||
inline String& operator = (std::nullptr_t) {
|
||||
m_ptr.reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
String& operator = (const char* str) {
|
||||
inline String& operator = (const char* str) {
|
||||
m_ptr = base::StrBuffer::createFromCString(str);
|
||||
return *this;
|
||||
}
|
||||
|
||||
String& operator = (const String& other){
|
||||
|
||||
inline String& operator = (const String& other){
|
||||
m_ptr = other.m_ptr;
|
||||
return *this;
|
||||
}
|
||||
|
||||
String& operator = (String&& other){
|
||||
|
||||
inline String& operator = (String&& other){
|
||||
m_ptr = std::forward<std::shared_ptr<base::StrBuffer>>(other.m_ptr);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool operator == (std::nullptr_t) const {
|
||||
inline bool operator == (std::nullptr_t) const {
|
||||
return m_ptr.get() == nullptr;
|
||||
}
|
||||
|
||||
bool operator != (std::nullptr_t) const {
|
||||
inline bool operator != (std::nullptr_t) const {
|
||||
return m_ptr.get() != nullptr;
|
||||
}
|
||||
|
||||
bool operator == (const char* str) const {
|
||||
inline bool operator == (const char* str) const {
|
||||
if(!m_ptr) return str == nullptr;
|
||||
if(str == nullptr) return false;
|
||||
if(m_ptr->getSize() != std::strlen(str)) return false;
|
||||
return base::StrBuffer::equals(m_ptr->getData(), str, m_ptr->getSize());
|
||||
}
|
||||
|
||||
bool operator != (const char* str) const {
|
||||
inline bool operator != (const char* str) const {
|
||||
return !operator == (str);
|
||||
}
|
||||
|
||||
bool operator == (const String &other) const {
|
||||
|
||||
inline bool operator == (const String &other) const {
|
||||
return base::StrBuffer::equals(m_ptr.get(), other.m_ptr.get());
|
||||
}
|
||||
|
||||
bool operator != (const String &other) const {
|
||||
|
||||
inline bool operator != (const String &other) const {
|
||||
return !operator == (other);
|
||||
}
|
||||
|
||||
explicit operator bool() const {
|
||||
|
||||
inline explicit operator bool() const {
|
||||
return m_ptr.operator bool();
|
||||
}
|
||||
|
||||
|
@ -148,7 +148,15 @@ public:
|
||||
return std::string((const char*) m_data, m_size);
|
||||
}
|
||||
|
||||
explicit operator bool() const {
|
||||
inline bool operator==(std::nullptr_t) const {
|
||||
return m_data == nullptr;
|
||||
}
|
||||
|
||||
inline bool operator!=(std::nullptr_t) const {
|
||||
return m_data != nullptr;
|
||||
}
|
||||
|
||||
inline explicit operator bool() const {
|
||||
return m_data != nullptr;
|
||||
}
|
||||
|
||||
@ -167,12 +175,42 @@ public:
|
||||
StringKeyLabel(const std::shared_ptr<base::StrBuffer>& memHandle, p_char8 data, v_buff_size size);
|
||||
StringKeyLabel(const char* constText);
|
||||
StringKeyLabel(const String& str);
|
||||
|
||||
bool operator==(const StringKeyLabel &other) const {
|
||||
|
||||
inline bool operator==(std::nullptr_t) const {
|
||||
return m_data == nullptr;
|
||||
}
|
||||
|
||||
inline bool operator!=(std::nullptr_t) const {
|
||||
return m_data != nullptr;
|
||||
}
|
||||
|
||||
inline bool operator==(const char* str) const {
|
||||
if(m_data == nullptr) return str == nullptr;
|
||||
if(str == nullptr) return false;
|
||||
if(m_size != std::strlen(str)) return false;
|
||||
return base::StrBuffer::equals(m_data, str, m_size);
|
||||
}
|
||||
|
||||
inline bool operator!=(const char* str) const {
|
||||
return !operator==(str);
|
||||
}
|
||||
|
||||
inline bool operator==(const String& str) const {
|
||||
if(m_data == nullptr) return str == nullptr;
|
||||
if(str == nullptr) return false;
|
||||
if(m_size != str->getSize()) return false;
|
||||
return base::StrBuffer::equals(m_data, str->getData(), m_size);
|
||||
}
|
||||
|
||||
inline bool operator!=(const String& str) const {
|
||||
return !operator==(str);
|
||||
}
|
||||
|
||||
inline bool operator==(const StringKeyLabel &other) const {
|
||||
return m_size == other.m_size && base::StrBuffer::equals(m_data, other.m_data, m_size);
|
||||
}
|
||||
|
||||
bool operator!=(const StringKeyLabel &other) const {
|
||||
|
||||
inline bool operator!=(const StringKeyLabel &other) const {
|
||||
return !(m_size == other.m_size && base::StrBuffer::equals(m_data, other.m_data, m_size));
|
||||
}
|
||||
|
||||
@ -191,15 +229,45 @@ public:
|
||||
StringKeyLabelCI(const std::shared_ptr<base::StrBuffer>& memHandle, p_char8 data, v_buff_size size);
|
||||
StringKeyLabelCI(const char* constText);
|
||||
StringKeyLabelCI(const String& str);
|
||||
|
||||
bool operator==(const StringKeyLabelCI &other) const {
|
||||
|
||||
inline bool operator==(std::nullptr_t) const {
|
||||
return m_data == nullptr;
|
||||
}
|
||||
|
||||
inline bool operator!=(std::nullptr_t) const {
|
||||
return m_data != nullptr;
|
||||
}
|
||||
|
||||
inline bool operator==(const char* str) const {
|
||||
if(m_data == nullptr) return str == nullptr;
|
||||
if(str == nullptr) return false;
|
||||
if(m_size != std::strlen(str)) return false;
|
||||
return base::StrBuffer::equalsCI(m_data, str, m_size);
|
||||
}
|
||||
|
||||
inline bool operator!=(const char* str) const {
|
||||
return !operator==(str);
|
||||
}
|
||||
|
||||
inline bool operator==(const String& str) const {
|
||||
if(m_data == nullptr) return str == nullptr;
|
||||
if(str == nullptr) return false;
|
||||
if(m_size != str->getSize()) return false;
|
||||
return base::StrBuffer::equalsCI(m_data, str->getData(), m_size);
|
||||
}
|
||||
|
||||
inline bool operator!=(const String& str) const {
|
||||
return !operator==(str);
|
||||
}
|
||||
|
||||
inline bool operator==(const StringKeyLabelCI &other) const {
|
||||
return m_size == other.m_size && base::StrBuffer::equalsCI(m_data, other.m_data, m_size);
|
||||
}
|
||||
|
||||
bool operator!=(const StringKeyLabelCI &other) const {
|
||||
|
||||
inline bool operator!=(const StringKeyLabelCI &other) const {
|
||||
return !(m_size == other.m_size && base::StrBuffer::equalsCI(m_data, other.m_data, m_size));
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@ -210,17 +278,49 @@ public:
|
||||
class StringKeyLabelCI_FAST : public MemoryLabel {
|
||||
public:
|
||||
|
||||
StringKeyLabelCI_FAST() : MemoryLabel() {};
|
||||
|
||||
StringKeyLabelCI_FAST(std::nullptr_t) : MemoryLabel() {}
|
||||
|
||||
StringKeyLabelCI_FAST(const std::shared_ptr<base::StrBuffer>& memHandle, p_char8 data, v_buff_size size);
|
||||
StringKeyLabelCI_FAST(const char* constText);
|
||||
StringKeyLabelCI_FAST(const String& str);
|
||||
|
||||
bool operator==(const StringKeyLabelCI_FAST &other) const {
|
||||
|
||||
inline bool operator==(std::nullptr_t) const {
|
||||
return m_data == nullptr;
|
||||
}
|
||||
|
||||
inline bool operator!=(std::nullptr_t) const {
|
||||
return m_data != nullptr;
|
||||
}
|
||||
|
||||
inline bool operator==(const char* str) const {
|
||||
if(m_data == nullptr) return str == nullptr;
|
||||
if(str == nullptr) return false;
|
||||
if(m_size != std::strlen(str)) return false;
|
||||
return base::StrBuffer::equalsCI_FAST(m_data, str, m_size);
|
||||
}
|
||||
|
||||
inline bool operator!=(const char* str) const {
|
||||
return !operator==(str);
|
||||
}
|
||||
|
||||
inline bool operator==(const String& str) const {
|
||||
if(m_data == nullptr) return str == nullptr;
|
||||
if(str == nullptr) return false;
|
||||
if(m_size != str->getSize()) return false;
|
||||
return base::StrBuffer::equalsCI_FAST(m_data, str->getData(), m_size);
|
||||
}
|
||||
|
||||
inline bool operator!=(const String& str) const {
|
||||
return !operator==(str);
|
||||
}
|
||||
|
||||
inline bool operator==(const StringKeyLabelCI_FAST &other) const {
|
||||
return m_size == other.m_size && base::StrBuffer::equalsCI_FAST(m_data, other.m_data, m_size);
|
||||
}
|
||||
|
||||
bool operator!=(const StringKeyLabelCI_FAST &other) const {
|
||||
|
||||
inline bool operator!=(const StringKeyLabelCI_FAST &other) const {
|
||||
return !(m_size == other.m_size && base::StrBuffer::equalsCI_FAST(m_data, other.m_data, m_size));
|
||||
}
|
||||
|
||||
|
@ -31,44 +31,84 @@ namespace oatpp { namespace test { namespace core { namespace data { namespace m
|
||||
|
||||
#include OATPP_CODEGEN_BEGIN(DTO)
|
||||
|
||||
ENUM(Enum0, v_int32)
|
||||
|
||||
ENUM(Enum1, v_int32,
|
||||
VALUE(V1, 1),
|
||||
VALUE(V2, 2),
|
||||
VALUE(V3, 3)
|
||||
)
|
||||
|
||||
ENUM(Enum2, v_int32,
|
||||
VALUE(NAME_1, 1, "name-1"),
|
||||
VALUE(NAME_2, 2, "name-2"),
|
||||
VALUE(NAME_3, 3, "name-3")
|
||||
)
|
||||
|
||||
ENUM(Enum2, v_int32,
|
||||
VALUE(NAME_1, 1, "name-1"),
|
||||
VALUE(NAME_2, 2, "name-2"),
|
||||
VALUE(NAME_3, 3, "name-3")
|
||||
ENUM(Enum3, v_int32,
|
||||
VALUE(V_1, 1, "v-1", "description_1"),
|
||||
VALUE(V_2, 2, "v-2", "description_2"),
|
||||
VALUE(V_3, 3, "v-3", "description_3")
|
||||
)
|
||||
|
||||
ENUM(Enum3, v_int32)
|
||||
|
||||
#include OATPP_CODEGEN_END(DTO)
|
||||
|
||||
void EnumTest::onRun() {
|
||||
|
||||
{
|
||||
OATPP_LOGI(TAG, "Check Meta...");
|
||||
{
|
||||
const auto &entries = oatpp::Enum<Enum0>::getEntries();
|
||||
OATPP_ASSERT(entries.size() == 0);
|
||||
}
|
||||
|
||||
{
|
||||
const auto &v = oatpp::Enum<Enum1>::getEntries();
|
||||
OATPP_ASSERT(v.size() == 3);
|
||||
OATPP_ASSERT(v[0].index == 0 && v[0].name == "V1" && v[0].value == Enum1::V1 && v[0].description == nullptr);
|
||||
OATPP_ASSERT(v[1].index == 1 && v[1].name == "V2" && v[1].value == Enum1::V2 && v[1].description == nullptr);
|
||||
OATPP_ASSERT(v[2].index == 2 && v[2].name == "V3" && v[2].value == Enum1::V3 && v[2].description == nullptr);
|
||||
}
|
||||
|
||||
{
|
||||
const auto &v = oatpp::Enum<Enum2>::getEntries();
|
||||
OATPP_ASSERT(v.size() == 3);
|
||||
OATPP_ASSERT(v[0].index == 0 && v[0].name == "name-1" && v[0].value == Enum2::NAME_1 && v[0].description == nullptr);
|
||||
OATPP_ASSERT(v[1].index == 1 && v[1].name == "name-2" && v[1].value == Enum2::NAME_2 && v[1].description == nullptr);
|
||||
OATPP_ASSERT(v[2].index == 2 && v[2].name == "name-3" && v[2].value == Enum2::NAME_3 && v[2].description == nullptr);
|
||||
}
|
||||
|
||||
{
|
||||
const auto &v = oatpp::Enum<Enum3>::getEntries();
|
||||
OATPP_ASSERT(v.size() == 3);
|
||||
OATPP_ASSERT(v[0].index == 0 && v[0].name == "v-1" && v[0].value == Enum3::V_1 && v[0].description == "description_1");
|
||||
OATPP_ASSERT(v[1].index == 1 && v[1].name == "v-2" && v[1].value == Enum3::V_2 && v[1].description == "description_2");
|
||||
OATPP_ASSERT(v[2].index == 2 && v[2].name == "v-3" && v[2].value == Enum3::V_3 && v[2].description == "description_3");
|
||||
}
|
||||
|
||||
OATPP_LOGI(TAG, "OK");
|
||||
}
|
||||
|
||||
{
|
||||
OATPP_LOGI(TAG, "Declaration...");
|
||||
OATPP_ASSERT(oatpp::Enum<Enum1>::Interpreter::notNull == false);
|
||||
OATPP_ASSERT(oatpp::Enum<Enum1>::NotNull::Interpreter::notNull == true);
|
||||
OATPP_ASSERT(oatpp::Enum<Enum2>::Interpreter::notNull == false);
|
||||
OATPP_ASSERT(oatpp::Enum<Enum2>::NotNull::Interpreter::notNull == true);
|
||||
|
||||
OATPP_ASSERT(oatpp::Enum<Enum1>::AsString::Interpreter::notNull == false);
|
||||
OATPP_ASSERT(oatpp::Enum<Enum1>::AsString::NotNull::Interpreter::notNull == true);
|
||||
OATPP_ASSERT(oatpp::Enum<Enum2>::AsString::Interpreter::notNull == false);
|
||||
OATPP_ASSERT(oatpp::Enum<Enum2>::AsString::NotNull::Interpreter::notNull == true);
|
||||
|
||||
OATPP_ASSERT(oatpp::Enum<Enum1>::AsInteger::Interpreter::notNull == false);
|
||||
OATPP_ASSERT(oatpp::Enum<Enum1>::AsInteger::NotNull::Interpreter::notNull == true);
|
||||
OATPP_ASSERT(oatpp::Enum<Enum2>::AsInteger::Interpreter::notNull == false);
|
||||
OATPP_ASSERT(oatpp::Enum<Enum2>::AsInteger::NotNull::Interpreter::notNull == true);
|
||||
|
||||
OATPP_ASSERT(oatpp::Enum<Enum1>::NotNull::AsString::Interpreter::notNull == true);
|
||||
OATPP_ASSERT(oatpp::Enum<Enum1>::NotNull::AsInteger::Interpreter::notNull == true);
|
||||
OATPP_ASSERT(oatpp::Enum<Enum2>::NotNull::AsString::Interpreter::notNull == true);
|
||||
OATPP_ASSERT(oatpp::Enum<Enum2>::NotNull::AsInteger::Interpreter::notNull == true);
|
||||
|
||||
auto pd1 = static_cast<const oatpp::data::mapping::type::__class::AbstractEnum::AbstractPolymorphicDispatcher*>(
|
||||
oatpp::Enum<Enum1>::Class::getType()->polymorphicDispatcher
|
||||
oatpp::Enum<Enum2>::Class::getType()->polymorphicDispatcher
|
||||
);
|
||||
|
||||
auto pd2 = static_cast<const oatpp::data::mapping::type::__class::AbstractEnum::AbstractPolymorphicDispatcher*>(
|
||||
oatpp::Enum<Enum1>::NotNull::Class::getType()->polymorphicDispatcher
|
||||
oatpp::Enum<Enum2>::NotNull::Class::getType()->polymorphicDispatcher
|
||||
);
|
||||
|
||||
OATPP_ASSERT(pd1->notNull == false);
|
||||
@ -80,57 +120,57 @@ void EnumTest::onRun() {
|
||||
{
|
||||
OATPP_LOGI(TAG, "Test Interpreter AsString...");
|
||||
oatpp::data::mapping::type::EnumInterpreterError e = oatpp::data::mapping::type::EnumInterpreterError::OK;
|
||||
auto inter = oatpp::Enum<Enum1>::AsString::Interpreter::toInterpretation(oatpp::Enum<Enum1>::AsString(Enum1::NAME_1), e);
|
||||
auto inter = oatpp::Enum<Enum2>::AsString::Interpreter::toInterpretation(oatpp::Enum<Enum2>::AsString(Enum2::NAME_1), e);
|
||||
OATPP_ASSERT(inter.valueType == oatpp::String::Class::getType());
|
||||
OATPP_ASSERT(e == oatpp::data::mapping::type::EnumInterpreterError::OK);
|
||||
|
||||
auto interValue = inter.staticCast<oatpp::String>();
|
||||
OATPP_ASSERT(interValue == "name-1");
|
||||
|
||||
oatpp::Void voidValue = oatpp::Enum<Enum1>::AsString::Interpreter::fromInterpretation(interValue, e);
|
||||
OATPP_ASSERT(voidValue.valueType == oatpp::Enum<Enum1>::AsString::Class::getType());
|
||||
oatpp::Void voidValue = oatpp::Enum<Enum2>::AsString::Interpreter::fromInterpretation(interValue, e);
|
||||
OATPP_ASSERT(voidValue.valueType == oatpp::Enum<Enum2>::AsString::Class::getType());
|
||||
OATPP_ASSERT(e == oatpp::data::mapping::type::EnumInterpreterError::OK);
|
||||
|
||||
auto value = voidValue.staticCast<oatpp::Enum<Enum1>::AsString>();
|
||||
OATPP_ASSERT(value == Enum1::NAME_1);
|
||||
auto value = voidValue.staticCast<oatpp::Enum<Enum2>::AsString>();
|
||||
OATPP_ASSERT(value == Enum2::NAME_1);
|
||||
OATPP_LOGI(TAG, "OK");
|
||||
}
|
||||
|
||||
{
|
||||
OATPP_LOGI(TAG, "Test Interpreter AsInteger...");
|
||||
oatpp::data::mapping::type::EnumInterpreterError e = oatpp::data::mapping::type::EnumInterpreterError::OK;
|
||||
auto inter = oatpp::Enum<Enum1>::AsInteger::Interpreter::toInterpretation(oatpp::Enum<Enum1>::AsInteger(Enum1::NAME_1), e);
|
||||
auto inter = oatpp::Enum<Enum2>::AsInteger::Interpreter::toInterpretation(oatpp::Enum<Enum2>::AsInteger(Enum2::NAME_1), e);
|
||||
OATPP_ASSERT(inter.valueType == oatpp::Int32::Class::getType());
|
||||
OATPP_ASSERT(e == oatpp::data::mapping::type::EnumInterpreterError::OK);
|
||||
|
||||
auto interValue = inter.staticCast<oatpp::Int32>();
|
||||
OATPP_ASSERT(interValue == static_cast<v_int32>(Enum1::NAME_1));
|
||||
OATPP_ASSERT(interValue == static_cast<v_int32>(Enum2::NAME_1));
|
||||
|
||||
oatpp::Void voidValue = oatpp::Enum<Enum1>::AsInteger::Interpreter::fromInterpretation(interValue, e);
|
||||
OATPP_ASSERT(voidValue.valueType == oatpp::Enum<Enum1>::AsInteger::Class::getType());
|
||||
oatpp::Void voidValue = oatpp::Enum<Enum2>::AsInteger::Interpreter::fromInterpretation(interValue, e);
|
||||
OATPP_ASSERT(voidValue.valueType == oatpp::Enum<Enum2>::AsInteger::Class::getType());
|
||||
OATPP_ASSERT(e == oatpp::data::mapping::type::EnumInterpreterError::OK);
|
||||
|
||||
auto value = voidValue.staticCast<oatpp::Enum<Enum1>::AsInteger>();
|
||||
OATPP_ASSERT(value == Enum1::NAME_1);
|
||||
auto value = voidValue.staticCast<oatpp::Enum<Enum2>::AsInteger>();
|
||||
OATPP_ASSERT(value == Enum2::NAME_1);
|
||||
OATPP_LOGI(TAG, "OK");
|
||||
}
|
||||
|
||||
{
|
||||
OATPP_LOGI(TAG, "Test default constructors and == operators...");
|
||||
oatpp::Enum<Enum1>::AsString e1;
|
||||
oatpp::Enum<Enum1>::AsString e2;
|
||||
oatpp::Enum<Enum2>::AsString e1;
|
||||
oatpp::Enum<Enum2>::AsString e2;
|
||||
|
||||
OATPP_ASSERT(!e1);
|
||||
OATPP_ASSERT(e1 == nullptr);
|
||||
OATPP_ASSERT(e1 == e2);
|
||||
OATPP_ASSERT(e2 == e1);
|
||||
|
||||
oatpp::Enum<Enum1>::NotNull e3;
|
||||
oatpp::Enum<Enum2>::NotNull e3;
|
||||
|
||||
OATPP_ASSERT(e1 == e3);
|
||||
OATPP_ASSERT(e3 == e1);
|
||||
|
||||
oatpp::Enum<Enum1>::AsInteger::NotNull e4;
|
||||
oatpp::Enum<Enum2>::AsInteger::NotNull e4;
|
||||
|
||||
OATPP_ASSERT(e1 == e4);
|
||||
OATPP_ASSERT(e4 == e1);
|
||||
@ -143,9 +183,9 @@ void EnumTest::onRun() {
|
||||
|
||||
{
|
||||
OATPP_LOGI(TAG, "Test value constructor and == operators...");
|
||||
oatpp::Enum<Enum1> e1(Enum1::NAME_1);
|
||||
oatpp::Enum<Enum1> e2(Enum1::NAME_1);
|
||||
oatpp::Enum<Enum1> e3;
|
||||
oatpp::Enum<Enum2> e1(Enum2::NAME_1);
|
||||
oatpp::Enum<Enum2> e2(Enum2::NAME_1);
|
||||
oatpp::Enum<Enum2> e3;
|
||||
|
||||
OATPP_ASSERT(e1);
|
||||
OATPP_ASSERT(e1 != nullptr);
|
||||
@ -153,64 +193,64 @@ void EnumTest::onRun() {
|
||||
OATPP_ASSERT(e1 != e3);
|
||||
OATPP_ASSERT(e3 != e1);
|
||||
|
||||
OATPP_ASSERT(e1 == Enum1::NAME_1);
|
||||
OATPP_ASSERT(e1 != Enum1::NAME_2);
|
||||
OATPP_ASSERT(e3 != Enum1::NAME_1);
|
||||
OATPP_ASSERT(e1 == Enum2::NAME_1);
|
||||
OATPP_ASSERT(e1 != Enum2::NAME_2);
|
||||
OATPP_ASSERT(e3 != Enum2::NAME_1);
|
||||
|
||||
OATPP_LOGI(TAG, "OK");
|
||||
}
|
||||
|
||||
{
|
||||
OATPP_LOGI(TAG, "Test copy-assignment operator...");
|
||||
oatpp::Enum<Enum1>::AsString e1;
|
||||
oatpp::Enum<Enum1>::AsInteger e2(Enum1::NAME_1);
|
||||
Enum1 ve;
|
||||
oatpp::Enum<Enum2>::AsString e1;
|
||||
oatpp::Enum<Enum2>::AsInteger e2(Enum2::NAME_1);
|
||||
Enum2 ve;
|
||||
|
||||
OATPP_ASSERT(e1.valueType == oatpp::Enum<Enum1>::AsString::Class::getType());
|
||||
OATPP_ASSERT(e2.valueType == oatpp::Enum<Enum1>::AsInteger::Class::getType());
|
||||
OATPP_ASSERT(e1.valueType == oatpp::Enum<Enum2>::AsString::Class::getType());
|
||||
OATPP_ASSERT(e2.valueType == oatpp::Enum<Enum2>::AsInteger::Class::getType());
|
||||
OATPP_ASSERT(e1.valueType != e2.valueType);
|
||||
|
||||
e1 = e2;
|
||||
|
||||
OATPP_ASSERT(e1.valueType == oatpp::Enum<Enum1>::AsString::Class::getType());
|
||||
OATPP_ASSERT(e2.valueType == oatpp::Enum<Enum1>::AsInteger::Class::getType());
|
||||
OATPP_ASSERT(e1.valueType == oatpp::Enum<Enum2>::AsString::Class::getType());
|
||||
OATPP_ASSERT(e2.valueType == oatpp::Enum<Enum2>::AsInteger::Class::getType());
|
||||
OATPP_ASSERT(e1.valueType != e2.valueType);
|
||||
|
||||
OATPP_ASSERT(e1 == e2);
|
||||
OATPP_ASSERT(e2 == e1);
|
||||
OATPP_ASSERT(e1.get() == e2.get());
|
||||
|
||||
e1 = Enum1::NAME_2;
|
||||
e1 = Enum2::NAME_2;
|
||||
|
||||
OATPP_ASSERT(e1 != e2);
|
||||
OATPP_ASSERT(e2 != e1);
|
||||
OATPP_ASSERT(e1.get() != e2.get());
|
||||
|
||||
OATPP_ASSERT(e1 == Enum1::NAME_2);
|
||||
OATPP_ASSERT(e2 == Enum1::NAME_1);
|
||||
OATPP_ASSERT(e1 == Enum2::NAME_2);
|
||||
OATPP_ASSERT(e2 == Enum2::NAME_1);
|
||||
|
||||
ve = e1;
|
||||
|
||||
OATPP_ASSERT(ve == Enum1::NAME_2);
|
||||
OATPP_ASSERT(ve == Enum2::NAME_2);
|
||||
|
||||
ve = e2;
|
||||
|
||||
OATPP_ASSERT(ve == Enum1::NAME_1);
|
||||
OATPP_ASSERT(ve == Enum2::NAME_1);
|
||||
|
||||
OATPP_LOGI(TAG, "OK");
|
||||
}
|
||||
|
||||
{
|
||||
OATPP_LOGI(TAG, "Test move-assignment operator...");
|
||||
oatpp::Enum<Enum1>::AsString e1;
|
||||
oatpp::Enum<Enum1>::AsInteger e2(Enum1::NAME_1);
|
||||
oatpp::Enum<Enum2>::AsString e1;
|
||||
oatpp::Enum<Enum2>::AsInteger e2(Enum2::NAME_1);
|
||||
|
||||
e1 = std::move(e2);
|
||||
|
||||
OATPP_ASSERT(e1);
|
||||
OATPP_ASSERT(!e2);
|
||||
|
||||
OATPP_ASSERT(e1 == Enum1::NAME_1);
|
||||
OATPP_ASSERT(e1 == Enum2::NAME_1);
|
||||
|
||||
OATPP_LOGI(TAG, "OK");
|
||||
}
|
||||
|
@ -32,130 +32,291 @@
|
||||
#include "oatpp-test/Checker.hpp"
|
||||
|
||||
namespace oatpp { namespace test { namespace core { namespace data { namespace share {
|
||||
|
||||
namespace {
|
||||
typedef oatpp::data::share::MemoryLabel MemoryLabel;
|
||||
typedef oatpp::data::share::StringKeyLabel StringKeyLabel;
|
||||
typedef oatpp::data::share::StringKeyLabelCI StringKeyLabelCI;
|
||||
typedef oatpp::data::share::StringKeyLabelCI_FAST StringKeyLabelCI_FAST;
|
||||
}
|
||||
|
||||
void MemoryLabelTest::onRun() {
|
||||
|
||||
oatpp::String sharedData = "big text goes here";
|
||||
oatpp::String key1 = "key1";
|
||||
oatpp::String key2 = "key2";
|
||||
oatpp::String key3 = "key3";
|
||||
oatpp::String key4 = "key4";
|
||||
|
||||
std::unordered_map<oatpp::data::share::StringKeyLabel, oatpp::data::share::MemoryLabel> stringMap;
|
||||
std::unordered_map<oatpp::data::share::StringKeyLabelCI, oatpp::data::share::MemoryLabel> stringMapCI;
|
||||
std::unordered_map<oatpp::data::share::StringKeyLabelCI_FAST, oatpp::data::share::MemoryLabel> stringMapCI_FAST;
|
||||
|
||||
// Case-Sensitive
|
||||
|
||||
stringMap[key1] = oatpp::data::share::MemoryLabel(sharedData.getPtr(), &sharedData->getData()[0], 3);
|
||||
stringMap[key2] = oatpp::data::share::MemoryLabel(sharedData.getPtr(), &sharedData->getData()[4], 4);
|
||||
stringMap[key3] = oatpp::data::share::MemoryLabel(sharedData.getPtr(), &sharedData->getData()[9], 4);
|
||||
stringMap[key4] = oatpp::data::share::MemoryLabel(sharedData.getPtr(), &sharedData->getData()[14], 4);
|
||||
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("big", stringMap["key1"].getData(), 3));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("text", stringMap["key2"].getData(), 4));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("goes", stringMap["key3"].getData(), 4));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("here", stringMap["key4"].getData(), 4));
|
||||
|
||||
OATPP_ASSERT(stringMap.find("Key1") == stringMap.end());
|
||||
OATPP_ASSERT(stringMap.find("Key2") == stringMap.end());
|
||||
OATPP_ASSERT(stringMap.find("Key3") == stringMap.end());
|
||||
OATPP_ASSERT(stringMap.find("Key4") == stringMap.end());
|
||||
|
||||
|
||||
// CI
|
||||
|
||||
stringMapCI[key1] = oatpp::data::share::MemoryLabel(sharedData.getPtr(), &sharedData->getData()[0], 3);
|
||||
stringMapCI[key2] = oatpp::data::share::MemoryLabel(sharedData.getPtr(), &sharedData->getData()[4], 4);
|
||||
stringMapCI[key3] = oatpp::data::share::MemoryLabel(sharedData.getPtr(), &sharedData->getData()[9], 4);
|
||||
stringMapCI[key4] = oatpp::data::share::MemoryLabel(sharedData.getPtr(), &sharedData->getData()[14], 4);
|
||||
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("big", stringMapCI["key1"].getData(), 3));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("text", stringMapCI["key2"].getData(), 4));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("goes", stringMapCI["key3"].getData(), 4));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("here", stringMapCI["key4"].getData(), 4));
|
||||
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("big", stringMapCI["KEY1"].getData(), 3));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("text", stringMapCI["KEY2"].getData(), 4));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("goes", stringMapCI["KEY3"].getData(), 4));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("here", stringMapCI["KEY4"].getData(), 4));
|
||||
|
||||
|
||||
// CI_FAST
|
||||
|
||||
stringMapCI_FAST[key1] = oatpp::data::share::MemoryLabel(sharedData.getPtr(), &sharedData->getData()[0], 3);
|
||||
stringMapCI_FAST[key2] = oatpp::data::share::MemoryLabel(sharedData.getPtr(), &sharedData->getData()[4], 4);
|
||||
stringMapCI_FAST[key3] = oatpp::data::share::MemoryLabel(sharedData.getPtr(), &sharedData->getData()[9], 4);
|
||||
stringMapCI_FAST[key4] = oatpp::data::share::MemoryLabel(sharedData.getPtr(), &sharedData->getData()[14], 4);
|
||||
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("big", stringMapCI_FAST["key1"].getData(), 3));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("text", stringMapCI_FAST["key2"].getData(), 4));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("goes", stringMapCI_FAST["key3"].getData(), 4));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("here", stringMapCI_FAST["key4"].getData(), 4));
|
||||
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("big", stringMapCI_FAST["KEY1"].getData(), 3));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("text", stringMapCI_FAST["KEY2"].getData(), 4));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("goes", stringMapCI_FAST["KEY3"].getData(), 4));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("here", stringMapCI_FAST["KEY4"].getData(), 4));
|
||||
|
||||
{
|
||||
|
||||
v_int32 iterationsCount = 100;
|
||||
|
||||
oatpp::String headersText =
|
||||
"header0: value0\r\n"
|
||||
"header1: value1\r\n"
|
||||
"header2: value2\r\n"
|
||||
"header3: value3\r\n"
|
||||
"header4: value4\r\n"
|
||||
"header5: value5\r\n"
|
||||
"header6: value6\r\n"
|
||||
"header7: value7\r\n"
|
||||
"header8: value8\r\n"
|
||||
"header9: value9\r\n"
|
||||
"\r\n";
|
||||
|
||||
{
|
||||
|
||||
oatpp::test::PerformanceChecker timer("timer");
|
||||
|
||||
for(v_int32 i = 0; i < iterationsCount; i ++) {
|
||||
|
||||
oatpp::parser::Caret caret(headersText);
|
||||
oatpp::web::protocol::http::Status status;
|
||||
oatpp::web::protocol::http::Headers headers;
|
||||
oatpp::web::protocol::http::Parser::parseHeaders(headers, headersText.getPtr(), caret, status);
|
||||
|
||||
OATPP_ASSERT(status.code == 0);
|
||||
OATPP_ASSERT(headers.getSize() == 10);
|
||||
|
||||
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<oatpp::data::share::StringKeyLabel>("header0").equals("value0", 6));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<oatpp::data::share::StringKeyLabel>("header1").equals("value1", 6));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<oatpp::data::share::StringKeyLabel>("header2").equals("value2", 6));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<oatpp::data::share::StringKeyLabel>("header3").equals("value3", 6));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<oatpp::data::share::StringKeyLabel>("header4").equals("value4", 6));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<oatpp::data::share::StringKeyLabel>("header5").equals("value5", 6));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<oatpp::data::share::StringKeyLabel>("header6").equals("value6", 6));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<oatpp::data::share::StringKeyLabel>("header7").equals("value7", 6));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<oatpp::data::share::StringKeyLabel>("header8").equals("value8", 6));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<oatpp::data::share::StringKeyLabel>("header9").equals("value9", 6));
|
||||
OATPP_LOGI(TAG, "StringKeyLabel default constructor...");
|
||||
StringKeyLabel s;
|
||||
StringKeyLabel s0;
|
||||
OATPP_ASSERT(!s);
|
||||
OATPP_ASSERT(s == nullptr);
|
||||
OATPP_ASSERT(s == s0);
|
||||
OATPP_ASSERT(s != "text");
|
||||
OATPP_ASSERT(s != oatpp::String("text"));
|
||||
OATPP_LOGI(TAG, "OK");
|
||||
}
|
||||
|
||||
{
|
||||
OATPP_LOGI(TAG, "StringKeyLabel nullptr constructor...");
|
||||
StringKeyLabel s(nullptr);
|
||||
OATPP_ASSERT(!s);
|
||||
OATPP_ASSERT(s == nullptr);
|
||||
OATPP_ASSERT(s != "text");
|
||||
OATPP_ASSERT(s != oatpp::String("text"));
|
||||
OATPP_LOGI(TAG, "OK");
|
||||
}
|
||||
|
||||
{
|
||||
OATPP_LOGI(TAG, "StringKeyLabel const char* constructor...");
|
||||
StringKeyLabel s("hello");
|
||||
StringKeyLabel s0;
|
||||
OATPP_ASSERT(s);
|
||||
OATPP_ASSERT(s != nullptr);
|
||||
OATPP_ASSERT(s != s0);
|
||||
OATPP_ASSERT(s0 != s);
|
||||
OATPP_ASSERT(s == "hello");
|
||||
OATPP_ASSERT(s == oatpp::String("hello"));
|
||||
OATPP_ASSERT(s != "text");
|
||||
OATPP_ASSERT(s != oatpp::String("text"));
|
||||
OATPP_LOGI(TAG, "OK");
|
||||
}
|
||||
|
||||
{
|
||||
OATPP_LOGI(TAG, "StringKeyLabel oatpp::String constructor...");
|
||||
StringKeyLabel s(oatpp::String("hello"));
|
||||
OATPP_ASSERT(s);
|
||||
OATPP_ASSERT(s != nullptr);
|
||||
OATPP_ASSERT(s == "hello");
|
||||
OATPP_ASSERT(s == oatpp::String("hello"));
|
||||
OATPP_ASSERT(s != "text");
|
||||
OATPP_ASSERT(s != oatpp::String("text"));
|
||||
OATPP_LOGI(TAG, "OK");
|
||||
}
|
||||
|
||||
{
|
||||
OATPP_LOGI(TAG, "StringKeyLabelCI default constructor...");
|
||||
StringKeyLabelCI s;
|
||||
StringKeyLabelCI s0;
|
||||
OATPP_ASSERT(!s);
|
||||
OATPP_ASSERT(s == nullptr);
|
||||
OATPP_ASSERT(s == s0);
|
||||
OATPP_ASSERT(s != "teXt");
|
||||
OATPP_ASSERT(s != oatpp::String("teXt"));
|
||||
OATPP_LOGI(TAG, "OK");
|
||||
}
|
||||
|
||||
{
|
||||
OATPP_LOGI(TAG, "StringKeyLabelCI nullptr constructor...");
|
||||
StringKeyLabelCI s(nullptr);
|
||||
OATPP_ASSERT(!s);
|
||||
OATPP_ASSERT(s == nullptr);
|
||||
OATPP_ASSERT(s != "teXt");
|
||||
OATPP_ASSERT(s != oatpp::String("teXt"));
|
||||
OATPP_LOGI(TAG, "OK");
|
||||
}
|
||||
|
||||
{
|
||||
OATPP_LOGI(TAG, "StringKeyLabelCI const char* constructor...");
|
||||
StringKeyLabelCI s("hello");
|
||||
StringKeyLabelCI s0;
|
||||
OATPP_ASSERT(s);
|
||||
OATPP_ASSERT(s != nullptr);
|
||||
OATPP_ASSERT(s != s0);
|
||||
OATPP_ASSERT(s0 != s);
|
||||
OATPP_ASSERT(s == "helLO");
|
||||
OATPP_ASSERT(s == oatpp::String("helLO"));
|
||||
OATPP_ASSERT(s != "text");
|
||||
OATPP_ASSERT(s != oatpp::String("teXt"));
|
||||
OATPP_LOGI(TAG, "OK");
|
||||
}
|
||||
|
||||
{
|
||||
OATPP_LOGI(TAG, "StringKeyLabelCI oatpp::String constructor...");
|
||||
StringKeyLabelCI s(oatpp::String("hello"));
|
||||
OATPP_ASSERT(s);
|
||||
OATPP_ASSERT(s != nullptr);
|
||||
OATPP_ASSERT(s == "helLO");
|
||||
OATPP_ASSERT(s == oatpp::String("helLO"));
|
||||
OATPP_ASSERT(s != "text");
|
||||
OATPP_ASSERT(s != oatpp::String("teXt"));
|
||||
OATPP_LOGI(TAG, "OK");
|
||||
}
|
||||
|
||||
{
|
||||
OATPP_LOGI(TAG, "StringKeyLabelCI_FAST default constructor...");
|
||||
StringKeyLabelCI_FAST s;
|
||||
StringKeyLabelCI_FAST s0;
|
||||
OATPP_ASSERT(!s);
|
||||
OATPP_ASSERT(s == nullptr);
|
||||
OATPP_ASSERT(s == s0);
|
||||
OATPP_ASSERT(s != "teXt");
|
||||
OATPP_ASSERT(s != oatpp::String("teXt"));
|
||||
OATPP_LOGI(TAG, "OK");
|
||||
}
|
||||
|
||||
{
|
||||
OATPP_LOGI(TAG, "StringKeyLabelCI_FAST nullptr constructor...");
|
||||
StringKeyLabelCI_FAST s(nullptr);
|
||||
OATPP_ASSERT(!s);
|
||||
OATPP_ASSERT(s == nullptr);
|
||||
OATPP_ASSERT(s != "teXt");
|
||||
OATPP_ASSERT(s != oatpp::String("teXt"));
|
||||
OATPP_LOGI(TAG, "OK");
|
||||
}
|
||||
|
||||
{
|
||||
OATPP_LOGI(TAG, "StringKeyLabelCI_FAST const char* constructor...");
|
||||
StringKeyLabelCI_FAST s("hello");
|
||||
StringKeyLabelCI_FAST s0;
|
||||
OATPP_ASSERT(s);
|
||||
OATPP_ASSERT(s != nullptr);
|
||||
OATPP_ASSERT(s != s0);
|
||||
OATPP_ASSERT(s0 != s);
|
||||
OATPP_ASSERT(s == "helLO");
|
||||
OATPP_ASSERT(s == oatpp::String("helLO"));
|
||||
OATPP_ASSERT(s != "text");
|
||||
OATPP_ASSERT(s != oatpp::String("teXt"));
|
||||
OATPP_LOGI(TAG, "OK");
|
||||
}
|
||||
|
||||
{
|
||||
OATPP_LOGI(TAG, "StringKeyLabelCI_FAST oatpp::String constructor...");
|
||||
StringKeyLabelCI_FAST s(oatpp::String("hello"));
|
||||
OATPP_ASSERT(s);
|
||||
OATPP_ASSERT(s != nullptr);
|
||||
OATPP_ASSERT(s == "helLO");
|
||||
OATPP_ASSERT(s == oatpp::String("helLO"));
|
||||
OATPP_ASSERT(s != "text");
|
||||
OATPP_ASSERT(s != oatpp::String("teXt"));
|
||||
OATPP_LOGI(TAG, "OK");
|
||||
}
|
||||
|
||||
{
|
||||
OATPP_LOGI(TAG, "general test...");
|
||||
|
||||
oatpp::String sharedData = "big text goes here";
|
||||
oatpp::String key1 = "key1";
|
||||
oatpp::String key2 = "key2";
|
||||
oatpp::String key3 = "key3";
|
||||
oatpp::String key4 = "key4";
|
||||
|
||||
std::unordered_map<StringKeyLabel, MemoryLabel> stringMap;
|
||||
std::unordered_map<StringKeyLabelCI, MemoryLabel> stringMapCI;
|
||||
std::unordered_map<StringKeyLabelCI_FAST, MemoryLabel> stringMapCI_FAST;
|
||||
|
||||
// Case-Sensitive
|
||||
|
||||
stringMap[key1] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[0], 3);
|
||||
stringMap[key2] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[4], 4);
|
||||
stringMap[key3] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[9], 4);
|
||||
stringMap[key4] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[14], 4);
|
||||
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("big", stringMap["key1"].getData(), 3));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("text", stringMap["key2"].getData(), 4));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("goes", stringMap["key3"].getData(), 4));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("here", stringMap["key4"].getData(), 4));
|
||||
|
||||
OATPP_ASSERT(stringMap.find("Key1") == stringMap.end());
|
||||
OATPP_ASSERT(stringMap.find("Key2") == stringMap.end());
|
||||
OATPP_ASSERT(stringMap.find("Key3") == stringMap.end());
|
||||
OATPP_ASSERT(stringMap.find("Key4") == stringMap.end());
|
||||
|
||||
|
||||
// CI
|
||||
|
||||
stringMapCI[key1] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[0], 3);
|
||||
stringMapCI[key2] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[4], 4);
|
||||
stringMapCI[key3] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[9], 4);
|
||||
stringMapCI[key4] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[14], 4);
|
||||
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("big", stringMapCI["key1"].getData(), 3));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("text", stringMapCI["key2"].getData(), 4));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("goes", stringMapCI["key3"].getData(), 4));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("here", stringMapCI["key4"].getData(), 4));
|
||||
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("big", stringMapCI["KEY1"].getData(), 3));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("text", stringMapCI["KEY2"].getData(), 4));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("goes", stringMapCI["KEY3"].getData(), 4));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("here", stringMapCI["KEY4"].getData(), 4));
|
||||
|
||||
|
||||
// CI_FAST
|
||||
|
||||
stringMapCI_FAST[key1] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[0], 3);
|
||||
stringMapCI_FAST[key2] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[4], 4);
|
||||
stringMapCI_FAST[key3] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[9], 4);
|
||||
stringMapCI_FAST[key4] = MemoryLabel(sharedData.getPtr(), &sharedData->getData()[14], 4);
|
||||
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("big", stringMapCI_FAST["key1"].getData(), 3));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("text", stringMapCI_FAST["key2"].getData(), 4));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("goes", stringMapCI_FAST["key3"].getData(), 4));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("here", stringMapCI_FAST["key4"].getData(), 4));
|
||||
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("big", stringMapCI_FAST["KEY1"].getData(), 3));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("text", stringMapCI_FAST["KEY2"].getData(), 4));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("goes", stringMapCI_FAST["KEY3"].getData(), 4));
|
||||
OATPP_ASSERT(oatpp::base::StrBuffer::equals("here", stringMapCI_FAST["KEY4"].getData(), 4));
|
||||
|
||||
{
|
||||
|
||||
v_int32 iterationsCount = 100;
|
||||
|
||||
oatpp::String headersText =
|
||||
"header0: value0\r\n"
|
||||
"header1: value1\r\n"
|
||||
"header2: value2\r\n"
|
||||
"header3: value3\r\n"
|
||||
"header4: value4\r\n"
|
||||
"header5: value5\r\n"
|
||||
"header6: value6\r\n"
|
||||
"header7: value7\r\n"
|
||||
"header8: value8\r\n"
|
||||
"header9: value9\r\n"
|
||||
"\r\n";
|
||||
|
||||
{
|
||||
|
||||
oatpp::test::PerformanceChecker timer("timer");
|
||||
|
||||
for (v_int32 i = 0; i < iterationsCount; i++) {
|
||||
|
||||
oatpp::parser::Caret caret(headersText);
|
||||
oatpp::web::protocol::http::Status status;
|
||||
oatpp::web::protocol::http::Headers headers;
|
||||
oatpp::web::protocol::http::Parser::parseHeaders(headers, headersText.getPtr(), caret, status);
|
||||
|
||||
OATPP_ASSERT(status.code == 0);
|
||||
OATPP_ASSERT(headers.getSize() == 10);
|
||||
|
||||
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<StringKeyLabel>("header0").equals("value0", 6));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<StringKeyLabel>("header1").equals("value1", 6));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<StringKeyLabel>("header2").equals("value2", 6));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<StringKeyLabel>("header3").equals("value3", 6));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<StringKeyLabel>("header4").equals("value4", 6));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<StringKeyLabel>("header5").equals("value5", 6));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<StringKeyLabel>("header6").equals("value6", 6));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<StringKeyLabel>("header7").equals("value7", 6));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<StringKeyLabel>("header8").equals("value8", 6));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<StringKeyLabel>("header9").equals("value9", 6));
|
||||
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<StringKeyLabel>("header0").equals("value0"));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<StringKeyLabel>("header1").equals("value1"));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<StringKeyLabel>("header2").equals("value2"));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<StringKeyLabel>("header3").equals("value3"));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<StringKeyLabel>("header4").equals("value4"));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<StringKeyLabel>("header5").equals("value5"));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<StringKeyLabel>("header6").equals("value6"));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<StringKeyLabel>("header7").equals("value7"));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<StringKeyLabel>("header8").equals("value8"));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<StringKeyLabel>("header9").equals("value9"));
|
||||
|
||||
}
|
||||
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<oatpp::data::share::StringKeyLabel>("header0").equals("value0"));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<oatpp::data::share::StringKeyLabel>("header1").equals("value1"));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<oatpp::data::share::StringKeyLabel>("header2").equals("value2"));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<oatpp::data::share::StringKeyLabel>("header3").equals("value3"));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<oatpp::data::share::StringKeyLabel>("header4").equals("value4"));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<oatpp::data::share::StringKeyLabel>("header5").equals("value5"));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<oatpp::data::share::StringKeyLabel>("header6").equals("value6"));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<oatpp::data::share::StringKeyLabel>("header7").equals("value7"));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<oatpp::data::share::StringKeyLabel>("header8").equals("value8"));
|
||||
OATPP_ASSERT(headers.getAsMemoryLabel<oatpp::data::share::StringKeyLabel>("header9").equals("value9"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
OATPP_LOGI(TAG, "OK");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user