ADC/tests/adc_devattr_test.cpp
Timur A. Fatkhullin 5dcc57707b due to GCC strange behavior with cast operator AdcDeviceAttribute class is now
has its own full "value holder" implementation without inheritance from
AdcValueHolder
2024-05-15 02:27:16 +03:00

47 lines
973 B
C++

#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
#include <doctest/doctest.h>
#include <iostream>
#include "../device/adc_device_attribute.h"
using namespace adc;
template <typename T>
struct V {
static T getter() { return _v; }
static void setter(const T& v) { _v = v; }
static bool validator(const T& v)
{
if (v < 1)
return false;
else
return true;
}
private:
inline static T _v = 1;
};
TEST_CASE("[ADC DEVICE ATTRIBUTE]")
{
double av = -10;
using vv = V<unsigned>;
using attr_t = AdcDeviceAttribute<std::string_view>;
attr_t attr("ATTR_A", adc::constants::AdcDefaultTrivialConvTypes, vv::getter, vv::setter);
attr = 10.7;
av = attr;
std::cout << "ATTR = " << av << "\n";
// std::cout << "ATTR = " << (unsigned)attr << "\n";
attr_t aw("ATTR_WO", adc::constants::AdcDefaultTrivialConvTypes, vv::setter);
std::cout << "ACC_TYPE: " << aw.accessType() << "\n";
}