lundi 6 avril 2015

Unit test against odbc-driver function involving SQLPOINTER

I want to write unit tests against the following functions. But I do not know how to create a non-null SQLPointer. Could someone help to build an example of unit test parameters for the following store_sqlwstr with the expected true/false return value please?


http://ift.tt/1Gi8OYX



bool store_sqlwstr(SQLPOINTER OutPointer, SQLSMALLINT BufferLength,
SQLSMALLINT *StringLengthPtr, const char *value) {
string str = value;
return store_sqlwstr(OutPointer, BufferLength, StringLengthPtr, str);
}


bool store_sqlwstr(SQLPOINTER OutPointer, SQLSMALLINT BufferLength,
SQLSMALLINT *StringLengthPtr, const string &value) {
assert(OutPointer != NULL);

sqlwchar_string sqlwstr;
int in_len, len, out_len;

// BufferLength is in bytes, not characters.
in_len = BufferLength / sizeof(SQLWCHAR);

utf8_to_swchar(value, sqlwstr);
len = swchar_strlcpy((SQLWCHAR *) OutPointer, sqlwstr.c_str(), in_len);

// Store the actual number of characters written into the buffer.
out_len = min(in_len - 1, len);
if (StringLengthPtr != NULL)
*StringLengthPtr = out_len * sizeof(SQLWCHAR);

return (len == out_len);
}


I have a test like:



TEST(outParams, testStoreSQLwstr) {
string test = "test";
string *p = &test;
SQLPOINTER outPointer = p;
SQLSMALLINT bufferLength = 100;
SQLSMALLINT *stringLengthPtr = new SQLSMALLINT(100);
const char *value = "string"; // 4 byte

EXPECT_TRUE(store_sqlwstr(outPointer, bufferLength, stringLengthPtr, value));}


But it is throwing errors pointer being freed was not allocated .


Thank you.


Aucun commentaire:

Enregistrer un commentaire