1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
#include <iostream>
#include <string>
#include <cstring>
#include <gtest/gtest.h>
#undef A_LIB_NAMESPACE
#define A_LIB_NAMESPACE Davix
#include "libs/alibxx/alibxx.hpp"
using namespace std;
struct DummyStruct{
std::string dude;
};
// instanciate and play with gates
TEST(ALibxx, StringToULong){
using namespace Davix;
std::string str_ulong("123456");
toType<unsigned long, std::string> conv;
unsigned long ul = conv(str_ulong);
ASSERT_EQ(ul, 123456);
str_ulong = "0";
ul= conv(str_ulong);
ASSERT_EQ(ul, 0);
try{
std::string str2 = "random string";
Davix::toType<unsigned long, std::string>()(str2);
FAIL();
}catch(TypeConvException & e){
// silent
}
try{
std::string str2 = "-15";
Davix::toType<unsigned long, std::string>()(str2);
FAIL();
}catch(TypeConvException & e){
// silent
}
unsigned long long super_long = std::numeric_limits<unsigned long long>::max();
std::ostringstream ss;
ss << super_long;
ss << super_long; // overflow
try{
ul =toType<unsigned long, std::string>()(ss.str());
FAIL();
}catch(...){
// silent
}
}
// instanciate and play with gates
TEST(ALibxx, StringToLong){
using namespace Davix;
std::string str_long("123456");
toType<long, std::string> conv;
long l = conv(str_long);
ASSERT_EQ(l, 123456);
str_long = "0";
l= conv(str_long);
ASSERT_EQ(l, 0);
try{
std::string str2 = "random string";
Davix::toType<long, std::string>()(str2);
FAIL();
}catch(TypeConvException & e){
// silent
}
str_long = "-9865743";
l = conv(str_long);
ASSERT_EQ(l, -9865743);
}
// instanciate and play with gates
TEST(ALibxx, StringToInt){
using namespace Davix;
std::string str_int("123456");
toType<int, std::string> conv;
int l = conv(str_int);
ASSERT_EQ(l, 123456);
str_int = "0";
l= conv(str_int);
ASSERT_EQ(l, 0);
try{
std::string str2 = "random string";
toType<int, std::string>()(str2);
FAIL();
}catch(TypeConvException & e){
// silent
}
str_int = "-9865743";
l = conv(str_int);
ASSERT_EQ(l, -9865743);
long long super_long = std::numeric_limits<long long>::max();
std::ostringstream ss;
ss << super_long;
ss << super_long; // overflow
try{
l =toType<int, std::string>()(ss.str());
FAIL();
}catch(...){
// silent
}
}
|