Database System 0.1.0
Advanced C++20 Database System with Multi-Backend Support
Loading...
Searching...
No Matches
value_formatter_test.cpp File Reference

Unit tests for value_formatter. More...

#include <gtest/gtest.h>
#include "database/query_builder/value_formatter.h"
Include dependency graph for value_formatter_test.cpp:

Go to the source code of this file.

Classes

class  ValueFormatterTest
 

Functions

 TEST_F (ValueFormatterTest, PostgreSQLStringEscaping)
 
 TEST_F (ValueFormatterTest, SQLiteStringEscaping)
 
 TEST_F (ValueFormatterTest, IdentifierQuoting)
 
 TEST_F (ValueFormatterTest, BooleanLiterals)
 
 TEST_F (ValueFormatterTest, NullLiteral)
 
 TEST_F (ValueFormatterTest, FormatString)
 
 TEST_F (ValueFormatterTest, FormatInteger)
 
 TEST_F (ValueFormatterTest, FormatDouble)
 
 TEST_F (ValueFormatterTest, FormatBoolean)
 

Detailed Description

Unit tests for value_formatter.

Definition in file value_formatter_test.cpp.

Function Documentation

◆ TEST_F() [1/9]

TEST_F ( ValueFormatterTest ,
BooleanLiterals  )

Definition at line 53 of file value_formatter_test.cpp.

53 {
54 value_formatter pg_fmt(database_types::postgres);
55 EXPECT_EQ(pg_fmt.bool_literal(true), "TRUE");
56 EXPECT_EQ(pg_fmt.bool_literal(false), "FALSE");
57
58}
Formats database values for different backends.

References database::query::value_formatter::bool_literal().

Here is the call graph for this function:

◆ TEST_F() [2/9]

TEST_F ( ValueFormatterTest ,
FormatBoolean  )

Definition at line 86 of file value_formatter_test.cpp.

86 {
87 value_formatter fmt(database_types::postgres);
88 bool value = true;
89 std::string formatted = fmt.format(value);
90 EXPECT_EQ(formatted, "TRUE");
91}

References database::query::value_formatter::format().

Here is the call graph for this function:

◆ TEST_F() [3/9]

TEST_F ( ValueFormatterTest ,
FormatDouble  )

Definition at line 79 of file value_formatter_test.cpp.

79 {
80 value_formatter fmt(database_types::postgres);
81 double value = 3.14159;
82 std::string formatted = fmt.format(value);
83 EXPECT_TRUE(formatted.find("3.14") != std::string::npos);
84}

References database::query::value_formatter::format().

Here is the call graph for this function:

◆ TEST_F() [4/9]

TEST_F ( ValueFormatterTest ,
FormatInteger  )

Definition at line 72 of file value_formatter_test.cpp.

72 {
73 value_formatter fmt(database_types::postgres);
74 int value = 42;
75 std::string formatted = fmt.format(value);
76 EXPECT_EQ(formatted, "42");
77}

References database::query::value_formatter::format().

Here is the call graph for this function:

◆ TEST_F() [5/9]

TEST_F ( ValueFormatterTest ,
FormatString  )

Definition at line 65 of file value_formatter_test.cpp.

65 {
66 value_formatter fmt(database_types::postgres);
67 std::string value = "test";
68 std::string formatted = fmt.format(value);
69 EXPECT_TRUE(formatted.find("'") != std::string::npos);
70}

References database::query::value_formatter::format().

Here is the call graph for this function:

◆ TEST_F() [6/9]

TEST_F ( ValueFormatterTest ,
IdentifierQuoting  )

Definition at line 45 of file value_formatter_test.cpp.

45 {
46 value_formatter pg_fmt(database_types::postgres);
47 EXPECT_EQ(pg_fmt.escape_identifier("table"), "\"table\"");
48
49 value_formatter sqlite_fmt(database_types::sqlite);
50 EXPECT_EQ(sqlite_fmt.escape_identifier("table"), "\"table\"");
51}

References database::query::value_formatter::escape_identifier().

Here is the call graph for this function:

◆ TEST_F() [7/9]

TEST_F ( ValueFormatterTest ,
NullLiteral  )

Definition at line 60 of file value_formatter_test.cpp.

60 {
61 value_formatter fmt(database_types::postgres);
62 EXPECT_EQ(fmt.null_literal(), "NULL");
63}

References database::query::value_formatter::null_literal().

Here is the call graph for this function:

◆ TEST_F() [8/9]

TEST_F ( ValueFormatterTest ,
PostgreSQLStringEscaping  )

Definition at line 22 of file value_formatter_test.cpp.

22 {
23 value_formatter fmt(database_types::postgres);
24
25 // Test single quote escaping
26 std::string input = "O'Brien";
27 std::string escaped = fmt.escape_string(input);
28 EXPECT_EQ(escaped, "O''Brien");
29
30 // Test backslash escaping
31 input = "path\\to\\file";
32 escaped = fmt.escape_string(input);
33 EXPECT_TRUE(escaped.find("\\\\") != std::string::npos);
34}

References database::query::value_formatter::escape_string().

Here is the call graph for this function:

◆ TEST_F() [9/9]

TEST_F ( ValueFormatterTest ,
SQLiteStringEscaping  )

Definition at line 36 of file value_formatter_test.cpp.

36 {
37 value_formatter fmt(database_types::sqlite);
38
39 // Test single quote escaping
40 std::string input = "O'Brien";
41 std::string escaped = fmt.escape_string(input);
42 EXPECT_EQ(escaped, "O''Brien");
43}

References database::query::value_formatter::escape_string().

Here is the call graph for this function: