From b0d869554b902c30f8a874b1e772a0241acf9f1f Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 17 Nov 2011 11:10:39 -0500 Subject: LLSD-14: Add tests from Simon's server-trunk changeset 3852648182db. That changeset provides most of the changes previously checked in on this Jira (viewer changeset 22b293aae639). Bring over the code he added to llsd_new_tut.cpp as well. --- indra/test/llsd_new_tut.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'indra/test/llsd_new_tut.cpp') diff --git a/indra/test/llsd_new_tut.cpp b/indra/test/llsd_new_tut.cpp index dd93b36f04..f332ad0ee2 100644 --- a/indra/test/llsd_new_tut.cpp +++ b/indra/test/llsd_new_tut.cpp @@ -742,6 +742,42 @@ namespace tut LLSD w = v; w = "nice day"; } + + { + SDAllocationCheck check("shared values test for threaded work", 9); + + //U32 start_llsd_count = LLSD::outstandingCount(); + + LLSD m = LLSD::emptyMap(); + + m["one"] = 1; + m["two"] = 2; + m["one_copy"] = m["one"]; // 3 (m, "one" and "two") + + m["undef_one"] = LLSD(); + m["undef_two"] = LLSD(); + m["undef_one_copy"] = m["undef_one"]; + + { // Ensure first_array gets freed to avoid counting it + LLSD first_array = LLSD::emptyArray(); + first_array.append(1.0f); + first_array.append(2.0f); + first_array.append(3.0f); // 7 + + m["array"] = first_array; + m["array_clone"] = first_array; + m["array_copy"] = m["array"]; // 7 + } + + m["string_one"] = "string one value"; + m["string_two"] = "string two value"; + m["string_one_copy"] = m["string_one"]; // 9 + + //U32 llsd_object_count = LLSD::outstandingCount(); + //std::cout << "Using " << (llsd_object_count - start_llsd_count) << " LLSD objects" << std::endl; + + //m.dumpStats(); + } } template<> template<> -- cgit v1.2.3 From 95fb0249e9f43d907608cc5840d1f8c0e49981d0 Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Thu, 1 Dec 2011 16:50:27 -0500 Subject: LLSD-14: Move LLSD::(outstanding|allocation)Count() to free functions. Free functions can be unconditionally compiled into the .o file, but conditionally hidden in the header file. Static class methods don't have that flexibility: without a declaration in the header file, you can't compile a function definition in the .cpp file. That makes it awkward to use the same llcommon build for production and for unit tests. Why make the function declarations conditional at all? These are debugging functions. They break the abstraction, they peek under the covers. Production code should not use them. Making them conditional on an #ifdef symbol in the unit-test source file means the compiler would reject any use by production code. Put differently, it allows us to assert with confidence that only unit tests do use them. Put new free functions in (lowercase) llsd namespace so as not to clutter global namespace. Tweak the one known consumer (llsd_new_tut.cpp) accordingly. --- indra/test/llsd_new_tut.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'indra/test/llsd_new_tut.cpp') diff --git a/indra/test/llsd_new_tut.cpp b/indra/test/llsd_new_tut.cpp index f332ad0ee2..b55a562e98 100644 --- a/indra/test/llsd_new_tut.cpp +++ b/indra/test/llsd_new_tut.cpp @@ -25,6 +25,7 @@ * $/LicenseInfo$ */ +#define LLSD_DEBUG_INFO #include #include "linden_common.h" #include "lltut.h" @@ -39,11 +40,11 @@ namespace tut private: U32 mOutstandingAtStart; public: - SDCleanupCheck() : mOutstandingAtStart(LLSD::outstandingCount()) { } + SDCleanupCheck() : mOutstandingAtStart(llsd::outstandingCount()) { } ~SDCleanupCheck() { ensure_equals("SDCleanupCheck", - LLSD::outstandingCount(), mOutstandingAtStart); + llsd::outstandingCount(), mOutstandingAtStart); } }; @@ -57,12 +58,12 @@ namespace tut SDAllocationCheck(const std::string& message, int expectedAllocations) : mMessage(message), mExpectedAllocations(expectedAllocations), - mAllocationAtStart(LLSD::allocationCount()) + mAllocationAtStart(llsd::allocationCount()) { } ~SDAllocationCheck() { ensure_equals(mMessage + " SDAllocationCheck", - LLSD::allocationCount() - mAllocationAtStart, + llsd::allocationCount() - mAllocationAtStart, mExpectedAllocations); } }; @@ -746,7 +747,7 @@ namespace tut { SDAllocationCheck check("shared values test for threaded work", 9); - //U32 start_llsd_count = LLSD::outstandingCount(); + //U32 start_llsd_count = llsd::outstandingCount(); LLSD m = LLSD::emptyMap(); @@ -773,7 +774,7 @@ namespace tut m["string_two"] = "string two value"; m["string_one_copy"] = m["string_one"]; // 9 - //U32 llsd_object_count = LLSD::outstandingCount(); + //U32 llsd_object_count = llsd::outstandingCount(); //std::cout << "Using " << (llsd_object_count - start_llsd_count) << " LLSD objects" << std::endl; //m.dumpStats(); -- cgit v1.2.3