Changeset 1363

Show
Ignore:
Timestamp:
08/08/08 23:56:06 (5 months ago)
Author:
jtv
Message:

Moved string_traits<result> to test helpers for reuse.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/test/test085.cxx

    r1359 r1363  
    2020        "Executing " name " as prepared statement yields different results.") \ 
    2121  PQXX_CHECK_EQUAL(lhs.empty(), false, "Result for " name " is empty.") 
    22  
    23  
    24 namespace 
    25 { 
    26 /// Dereference result element as string 
    27 struct deref_field 
    28 { 
    29   string operator()(const result::field &f) const { return f.c_str(); } 
    30 }; 
    31 } 
    32  
    33 namespace pqxx 
    34 { 
    35 // Support string conversion for result objects for debug output. 
    36 template<> struct string_traits<result> 
    37 { 
    38   static const char *name() { return "pqxx::result"; } 
    39   static bool has_null() { return true; } 
    40   static bool is_null(result r) { return r.empty(); } 
    41   static result null() { return result(); } 
    42   static void from_string(const char Str[], result &Obj); // Not needed 
    43   static string to_string(result Obj) 
    44   { 
    45     if (is_null(Obj)) return "<empty>"; 
    46  
    47     string out; 
    48     for (result::const_iterator row = Obj.begin(); row != Obj.end(); ++row) 
    49     { 
    50       out += "{" + 
    51         separated_list(", ", row.begin(), row.end(), deref_field()) + 
    52         "}"; 
    53     } 
    54     return out; 
    55   } 
    56 }; 
    57 } 
    5822 
    5923 
  • trunk/test/test_helpers.hxx

    r1361 r1363  
    202202 
    203203} // namespace test 
     204 
     205 
     206namespace 
     207{ 
     208PGSTD::string deref_field(const result::field &f) { return f.c_str(); } 
     209} // namespace 
     210 
     211 
     212// Support string conversion on result objects for debug output. 
     213template<> struct string_traits<result> 
     214{ 
     215  static const char *name() { return "pqxx::result"; } 
     216  static bool has_null() { return true; } 
     217  static bool is_null(result r) { return r.empty(); } 
     218  static result null() { return result(); } 
     219  static void from_string(const char Str[], result &Obj); // Not needed 
     220  static PGSTD::string to_string(result Obj) 
     221  { 
     222    if (is_null(Obj)) return "<empty>"; 
     223 
     224    PGSTD::string out; 
     225    for (result::const_iterator row = Obj.begin(); row != Obj.end(); ++row) 
     226    { 
     227      out += "{" + 
     228        separated_list(", ", row.begin(), row.end(), deref_field) + 
     229        "}"; 
     230    } 
     231    return out; 
     232  } 
     233}; 
     234 
     235// Support string conversion on vector<string> for debug output. 
     236template<> struct string_traits<PGSTD::vector<PGSTD::string> > 
     237{ 
     238  typedef PGSTD::vector<PGSTD::string> subject_type; 
     239  static const char *name() { return "vector<string>"; } 
     240  static bool has_null() { return false; } 
     241  static bool is_null(subject_type) { return false; } 
     242  static subject_type null(); // Not needed 
     243  static void from_string(const char Str[], subject_type &Obj); // Not needed 
     244  static PGSTD::string to_string(const subject_type &Obj) 
     245                                 { return separated_list("; ", Obj); } 
     246}; 
    204247} // namespace pqxx 
    205248