@@ -148,35 +148,37 @@ void FromIntervalToExpectedTest(SQLINTERVAL interval_type, CType interval_value,
148148
149149 EXPECT_EQ (*returned_val, expected_val);
150150}
151-
152151template <typename SrcType>
153152void FromArithmeticToStringTest (SrcType src_val,
154153 std::string const & expected_val,
155154 SQLSMALLINT dest_type,
156155 std::string const & expected_state = " " ,
157156 std::string const & expected_message = " " ) {
158157 SQLPOINTER buf = malloc (50 );
159- DataBuffer data = {dest_type, buf, 50 , nullptr };
158+
159+ SQLLEN result_len = 0 ;
160+
161+ DataBuffer data = {dest_type, buf, 50 , &result_len};
160162 DSValue ds_value;
161163
162164 ArithmeticToDSValue<SrcType>(src_val, ds_value);
165+
163166 StatusRecord status_record =
164167 ConvertFromArithmeticDSValue<SrcType>(ds_value, data);
168+
165169 if (expected_state.empty () || expected_state == SQLStates::k_01S07 ()) {
166- std::string returned_val =
167- reinterpret_cast <char *>(static_cast <SQLCHAR *>(data.buf ));
168- if constexpr (std::is_same_v<SrcType, SQLCHAR *>) {
169- EXPECT_EQ (returned_val, expected_val);
170- } else if constexpr (std::is_same_v<SrcType, float >) {
171- EXPECT_EQ (std::stof (returned_val), std::stof (expected_val));
170+ std::string returned_val (reinterpret_cast <char *>(data.buf ));
171+
172+ if constexpr (std::is_same_v<SrcType, float >) {
173+ EXPECT_FLOAT_EQ (std::stof (returned_val), std::stof (expected_val));
172174 } else if constexpr (std::is_same_v<SrcType, double >) {
173- EXPECT_EQ (std::stod (returned_val), std::stod (expected_val));
175+ EXPECT_DOUBLE_EQ (std::stod (returned_val), std::stod (expected_val));
174176 } else if constexpr (std::is_same_v<SrcType, int >) {
175177 EXPECT_EQ (std::stoi (returned_val), std::stoi (expected_val));
176178 } else if constexpr (std::is_same_v<SrcType, int64_t >) {
177- EXPECT_EQ (std::stol (returned_val), std::stol (expected_val));
179+ EXPECT_EQ (std::stoll (returned_val), std::stoll (expected_val));
178180 } else {
179- EXPECT_EQ (std::stod ( returned_val), std::stod ( expected_val) );
181+ EXPECT_EQ (returned_val, expected_val);
180182 }
181183 EXPECT_EQ (expected_message, status_record.message );
182184 } else {
@@ -1946,7 +1948,7 @@ TEST(ConvertFromBytesDSValue, WCharDataExactFit) {
19461948
19471949 StringToDSValue (input, source_dsval);
19481950 DataBuffer dest_data;
1949- std::vector<SQLWCHAR > dest_buf (4 , 0 );
1951+ std::vector<SQLWCHAR > dest_buf (5 , 0 );
19501952 dest_data.buf = dest_buf.data ();
19511953 dest_data.buflen = dest_buf.size () * sizeof (SQLWCHAR );
19521954 SQLLEN result_len = 0 ;
@@ -1955,9 +1957,8 @@ TEST(ConvertFromBytesDSValue, WCharDataExactFit) {
19551957
19561958 auto status = ConvertFromBytesDSValue (source_dsval, dest_data);
19571959 ASSERT_TRUE (status.ok ());
1958- std::wstring return_val (dest_buf.begin (), dest_buf.end ());
1959- ASSERT_EQ (return_val,
1960- L" YWIA" ); // SQL_C_WCHAR returns data is base64
1960+ std::wstring return_val (dest_buf.data ());
1961+ ASSERT_EQ (return_val, L" YWIA" );
19611962}
19621963
19631964TEST (ConvertFromBytesDSValue, WCharDataWithTruncation) {
@@ -1966,9 +1967,11 @@ TEST(ConvertFromBytesDSValue, WCharDataWithTruncation) {
19661967 StringToDSValue (input, source_dsval);
19671968
19681969 DataBuffer dest_data;
1969- std::vector<SQLWCHAR > dest_buf (4 );
1970+
1971+ std::vector<SQLWCHAR > dest_buf (5 , 0 );
19701972 dest_data.buf = dest_buf.data ();
1971- dest_data.buflen = 4 * sizeof (SQLWCHAR );
1973+ dest_data.buflen = dest_buf.size () * sizeof (SQLWCHAR ); // force truncation
1974+
19721975 SQLLEN result_len = 0 ;
19731976 dest_data.result_len = &result_len;
19741977 dest_data.type = SQL_C_WCHAR ;
0 commit comments