/*************************************************************************** * * Copyright (c) 2009 Baidu.com, Inc. All Rights Reserved * $Id: test_var_utils.cpp,v 1.3 2010/04/28 12:45:33 scmpf Exp $ * **************************************************************************/ #include "bsl/var/implement.h" #include "bsl/var/utils.h" #include "bsl/var/assign.h" #include "bsl/var/var_traits.h" /** * @file test_var_utils.cpp * @author chenxm(chenxiaoming@baidu.com) * @date 2009/05/07 15:35:38 * @version $Revision: 1.3 $ * @brief * **/ #include #include #define see(x) do{ \ std::cerr<<__FILE__<<":"<<__LINE__<<": " <<(#x)<<" = "<<(x)<<" ("<" ); printf("i32, 0: %s", res.c_str() ); } { bsl::string res; dump_to_string( i32, res, 999, "" ); printf("i32, 999: %s", res.c_str() ); } { bsl::string res; dump_to_string( dict, res, 0, "" ); printf("dict, 0: %s", res.c_str() ); } { bsl::string res; dump_to_string( dict, res, 1, "" ); printf("dict, 1: %s", res.c_str() ); } { bsl::string res; dump_to_string( dict, res, 3, "" ); printf("dict, 3: %s", res.c_str() ); } { bsl::string res; dump_to_string( i32, res, 0, "\n" ); printf("i32, 0: %s\n", res.c_str() ); } { bsl::string res; dump_to_string( i32, res, 999, "\n" ); printf("i32, 999: %s\n", res.c_str() ); } { bsl::string res; dump_to_string( dict, res, 0, "\n" ); printf("dict, 0: %s\n", res.c_str() ); } { bsl::string res; dump_to_string( dict, res, 1, "\n" ); printf("dict, 1: %s\n", res.c_str() ); } { bsl::string res; dump_to_string( dict, res, 3, "\n" ); printf("dict, 3: %s\n", res.c_str() ); } } void test_assign(){ bsl::var::Int32 i32(123); bsl::var::Int64 i64(456); bsl::var::String str("hello"); //array bsl::var::Array arr; bsl::var::assign( arr, i32, i64 ); assert( arr.size() == 2 ); assert( arr[0].to_int32() == 123 ); assert( arr[1].to_int64() == 456 ); bsl::var::assign( arr, str ); assert( arr.size() == 1 ); assert( arr[0].to_string() == "hello" ); //dict bsl::var::Dict dict; bsl::var::assign( dict, "haha", i32, "hehe", i64 ); assert( dict.size() == 2 ); assert( dict["haha"].to_int32() == 123 ); assert( dict["hehe"].to_int64() == 456 ); bsl::var::assign( dict, "crazy", str ); assert( dict.size() == 1 ); assert( dict["crazy"].to_string() == "hello" ); } template void test_traits_type(){ bsl::var::Number v; assert(v.get_mask() == bsl::var::var_traits::MASK); } void test_traits(){ test_traits_type(); test_traits_type(); test_traits_type(); test_traits_type(); test_traits_type(); test_traits_type(); test_traits_type(); test_traits_type(); } int main(){ test_dump_to_string(); test_assign(); test_traits(); return 0; } /* vim: set ts=4 sw=4 sts=4 tw=100 */