Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .build-variables
Submodule .build-variables added at f8fad0
11 changes: 11 additions & 0 deletions docs/testing/doctest_quickstart.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# doctest quickstart

This repository uses a header-only doctest setup with a thin helpers/compat layer.
- Enable: `autobuild configure -c RelWithDebInfoOS -- -DLL_TESTS=ON`
- Build targets: `llcommon_doctest`, `llmath_doctest`, `llcorehttp_doctest`
- Run: `ctest -C RelWithDebInfo -R "(llcommon_doctest|llmath_doctest|llcorehttp_doctest)" -V`

Notes:
- Hand-authored tests are marked with `// DOCTEST_SKIP_AUTOGEN` to keep the generator idempotent.
- `LL_CHECK_*` helpers provide clearer output for floats, buffers, wide strings, and ranges.
- HTTP fake layer provides zero-latency transport, monotonic clock, per-handle queued responses (redirects/retries/cancels) — tests stay network/IO-free.
3 changes: 2 additions & 1 deletion indra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ project(${ROOT_PROJECT_NAME})

set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" "${CMAKE_CURRENT_BINARY_DIR}")

enable_testing()

include(conanbuildinfo OPTIONAL RESULT_VARIABLE USE_CONAN )
if( USE_CONAN )
set( USE_CONAN ON )
Expand Down Expand Up @@ -147,4 +149,3 @@ if (LL_TESTS)
# individual apps can add themselves as dependencies
add_subdirectory(${INTEGRATION_TESTS_PREFIX}integration_tests)
endif (LL_TESTS)

1 change: 1 addition & 0 deletions indra/cmake/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(cmake_SOURCE_FILES
DeploySharedLibs.cmake
Discord.cmake
DragDrop.cmake
Doctest.cmake
EXPAT.cmake
FindAutobuild.cmake
FreeType.cmake
Expand Down
6 changes: 6 additions & 0 deletions indra/cmake/Doctest.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- cmake -*-
include_guard(GLOBAL)

if(NOT DEFINED DOCTEST_INCLUDE_DIR)
set(DOCTEST_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/extern/doctest")
endif()
21 changes: 21 additions & 0 deletions indra/extern/doctest/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016-2024 Viktor Kirilov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
7,140 changes: 7,140 additions & 0 deletions indra/extern/doctest/doctest.h

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions indra/llcommon/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ add_dependencies(llcommon stage_third_party_libs)

if (LL_TESTS)
include(LLAddBuildTest)
include(Doctest)
SET(llcommon_TEST_SOURCE_FILES
# unit-testing llcommon is not possible right now as the test-harness *itself* depends upon llcommon, causing a circular dependency. Add your 'unit' tests as integration tests for now.
)
Expand Down Expand Up @@ -336,4 +337,6 @@ if (LL_TESTS)
## throwing and catching exceptions.
##LL_ADD_INTEGRATION_TEST(llexception "" "${test_libs}")

add_subdirectory(tests_doctest)

endif (LL_TESTS)
23 changes: 23 additions & 0 deletions indra/llcommon/tests_doctest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
file(GLOB LLCOMMON_DOCTEST_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/*_doctest.cpp"
)

add_executable(llcommon_doctest
${LLCOMMON_DOCTEST_SOURCES}
${CMAKE_SOURCE_DIR}/test/doctest_main.cpp
)

target_include_directories(llcommon_doctest
PRIVATE
${CMAKE_SOURCE_DIR}
${DOCTEST_INCLUDE_DIR}
${CMAKE_SOURCE_DIR}/test
${CMAKE_SOURCE_DIR}/llcommon
${CMAKE_SOURCE_DIR}/llcommon/tests
)

target_link_libraries(llcommon_doctest
llcommon
)

add_test(NAME llcommon_doctest COMMAND llcommon_doctest)
167 changes: 167 additions & 0 deletions indra/llcommon/tests_doctest/apply_test_doctest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/**
* @file apply_test_doctest.cpp
* @date 2025-02-18
* @brief doctest: unit tests for apply
*
* $LicenseInfo:firstyear=2025&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2025, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/

// ---------------------------------------------------------------------------
// Auto-generated from apply_test.cpp at 2025-10-16T18:47:16Z
// This file is a TODO stub produced by gen_tut_to_doctest.py.
// ---------------------------------------------------------------------------
#include "doctest.h"
#include "ll_doctest_helpers.h"
#include "tut_compat_doctest.h"
#include "linden_common.h"
#include "apply.h"
#include <iomanip>
#include "llsd.h"
#include "llsdutil.h"
#include <array>
#include <string>
#include <vector>

TUT_SUITE("llcommon")
{
TUT_CASE("apply_test::object_test_1")
{
DOCTEST_FAIL("TODO: convert apply_test.cpp::object::test<1> from TUT to doctest");
// Original snippet:
// template<> template<>
// void object::test<1>()
// {
// set_test_name("apply(tuple)");
// LL::apply(statics::various,
// std::make_tuple(statics::b, statics::i, statics::f, statics::s,
// statics::uu, statics::dt, statics::uri, statics::bin));
// ensure("apply(tuple) failed", statics::called);
// }
}

TUT_CASE("apply_test::object_test_2")
{
DOCTEST_FAIL("TODO: convert apply_test.cpp::object::test<2> from TUT to doctest");
// Original snippet:
// template<> template<>
// void object::test<2>()
// {
// set_test_name("apply(array)");
// LL::apply(statics::ints, statics::fibs);
// ensure("apply(array) failed", statics::called);
// }
}

TUT_CASE("apply_test::object_test_3")
{
DOCTEST_FAIL("TODO: convert apply_test.cpp::object::test<3> from TUT to doctest");
// Original snippet:
// template<> template<>
// void object::test<3>()
// {
// set_test_name("apply(vector)");
// LL::apply(statics::strings, statics::quick);
// ensure("apply(vector) failed", statics::called);
// }
}

TUT_CASE("apply_test::object_test_4")
{
DOCTEST_FAIL("TODO: convert apply_test.cpp::object::test<4> from TUT to doctest");
// Original snippet:
// template<> template<>
// void object::test<4>()
// {
// set_test_name("apply(LLSD())");
// LL::apply(statics::voidfunc, LLSD());
// ensure("apply(LLSD()) failed", statics::called);
// }
}

TUT_CASE("apply_test::object_test_5")
{
DOCTEST_FAIL("TODO: convert apply_test.cpp::object::test<5> from TUT to doctest");
// Original snippet:
// template<> template<>
// void object::test<5>()
// {
// set_test_name("apply(fn(int), LLSD scalar)");
// LL::apply(statics::intfunc, LLSD(statics::i));
// ensure("apply(fn(int), LLSD scalar) failed", statics::called);
// }
}

TUT_CASE("apply_test::object_test_6")
{
DOCTEST_FAIL("TODO: convert apply_test.cpp::object::test<6> from TUT to doctest");
// Original snippet:
// template<> template<>
// void object::test<6>()
// {
// set_test_name("apply(fn(LLSD), LLSD scalar)");
// // This test verifies that LLSDParam<LLSD> doesn't send the compiler
// // into infinite recursion when the target is itself LLSD.
// LL::apply(statics::sdfunc, LLSD(statics::i));
// ensure("apply(fn(LLSD), LLSD scalar) failed", statics::called);
// }
}

TUT_CASE("apply_test::object_test_7")
{
DOCTEST_FAIL("TODO: convert apply_test.cpp::object::test<7> from TUT to doctest");
// Original snippet:
// template<> template<>
// void object::test<7>()
// {
// set_test_name("apply(LLSD array)");
// LL::apply(statics::various,
// llsd::array(statics::b, statics::i, statics::f, statics::s,
// statics::uu, statics::dt, statics::uri, statics::bin));
// ensure("apply(LLSD array) failed", statics::called);
// }
}

TUT_CASE("apply_test::object_test_8")
{
DOCTEST_FAIL("TODO: convert apply_test.cpp::object::test<8> from TUT to doctest");
// Original snippet:
// template<> template<>
// void object::test<8>()
// {
// set_test_name("VAPPLY()");
// // Make a std::array<std::string> from statics::quick. We can't call a
// // variadic function with a data structure of dynamic length.
// std::array<std::string, 5> strray;
// for (size_t i = 0; i < strray.size(); ++i)
// strray[i] = statics::quick[i];
// // This doesn't work: the compiler doesn't know which overload of
// // collect() to pass to LL::apply().
// // LL::apply(statics::collect, strray);
// // That's what VAPPLY() is for.
// VAPPLY(statics::collect, strray);
// ensure("VAPPLY() failed", statics::called);
// ensure_equals("collected mismatch", statics::collected, statics::quick);
// }
}

}

127 changes: 127 additions & 0 deletions indra/llcommon/tests_doctest/bitpack_test_doctest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/**
* @file bitpack_test_doctest.cpp
* @date 2025-02-18
* @brief doctest: unit tests for bitpack
*
* $LicenseInfo:firstyear=2025&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2025, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/

// ---------------------------------------------------------------------------
// Auto-generated from bitpack_test.cpp at 2025-10-16T18:47:16Z
// This file is a TODO stub produced by gen_tut_to_doctest.py.
// ---------------------------------------------------------------------------
#include "doctest.h"
#include "ll_doctest_helpers.h"
#include "tut_compat_doctest.h"
#include "linden_common.h"
#include "../llbitpack.h"

TUT_SUITE("llcommon")
{
TUT_CASE("bitpack_test::bit_pack_object_t_test_1")
{
DOCTEST_FAIL("TODO: convert bitpack_test.cpp::bit_pack_object_t::test<1> from TUT to doctest");
// Original snippet:
// template<> template<>
// void bit_pack_object_t::test<1>()
// {
// U8 packbuffer[255];
// U8 unpackbuffer[255];
// int pack_bufsize = 0;
// int unpack_bufsize = 0;

// LLBitPack bitpack(packbuffer, 255);

// char str[] = "SecondLife is a 3D virtual world";
// int len = sizeof(str);
// pack_bufsize = bitpack.bitPack((U8*) str, len*8);
// pack_bufsize = bitpack.flushBitPack();

// LLBitPack bitunpack(packbuffer, pack_bufsize*8);
// unpack_bufsize = bitunpack.bitUnpack(unpackbuffer, len*8);
// ensure("bitPack: unpack size should be same as string size prior to pack", len == unpack_bufsize);
// ensure_memory_matches("str->bitPack->bitUnpack should be equal to string", str, len, unpackbuffer, unpack_bufsize);
// }
}

TUT_CASE("bitpack_test::bit_pack_object_t_test_2")
{
DOCTEST_FAIL("TODO: convert bitpack_test.cpp::bit_pack_object_t::test<2> from TUT to doctest");
// Original snippet:
// template<> template<>
// void bit_pack_object_t::test<2>()
// {
// U8 packbuffer[255];
// U8 unpackbuffer[255];
// int pack_bufsize = 0;

// LLBitPack bitpack(packbuffer, 255);

// char str[] = "SecondLife";
// int len = sizeof(str);
// pack_bufsize = bitpack.bitPack((U8*) str, len*8);
// pack_bufsize = bitpack.flushBitPack();

// LLBitPack bitunpack(packbuffer, pack_bufsize*8);
// bitunpack.bitUnpack(&unpackbuffer[0], 8);
// ensure("bitPack: individual unpack: 0", unpackbuffer[0] == (U8) str[0]);
// bitunpack.bitUnpack(&unpackbuffer[0], 8);
// ensure("bitPack: individual unpack: 1", unpackbuffer[0] == (U8) str[1]);
// bitunpack.bitUnpack(&unpackbuffer[0], 8);
// ensure("bitPack: individual unpack: 2", unpackbuffer[0] == (U8) str[2]);
// bitunpack.bitUnpack(&unpackbuffer[0], 8);
// ensure("bitPack: individual unpack: 3", unpackbuffer[0] == (U8) str[3]);
// bitunpack.bitUnpack(&unpackbuffer[0], 8);
// ensure("bitPack: individual unpack: 4", unpackbuffer[0] == (U8) str[4]);
// bitunpack.bitUnpack(&unpackbuffer[0], 8);
// ensure("bitPack: individual unpack: 5", unpackbuffer[0] == (U8) str[5]);
// bitunpack.bitUnpack(unpackbuffer, 8*4); // Life
// ensure_memory_matches("bitPack: 4 bytes unpack:", unpackbuffer, 4, str+6, 4);
// }
}

TUT_CASE("bitpack_test::bit_pack_object_t_test_3")
{
DOCTEST_FAIL("TODO: convert bitpack_test.cpp::bit_pack_object_t::test<3> from TUT to doctest");
// Original snippet:
// template<> template<>
// void bit_pack_object_t::test<3>()
// {
// U8 packbuffer[255];
// int pack_bufsize = 0;

// LLBitPack bitpack(packbuffer, 255);
// U32 num = 0x41fab67a;
// pack_bufsize = bitpack.bitPack((U8*)&num, 8*sizeof(U32));
// pack_bufsize = bitpack.flushBitPack();

// LLBitPack bitunpack(packbuffer, pack_bufsize*8);
// U32 res = 0;
// // since packing and unpacking is done on same machine in the unit test run,
// // endianness should not matter
// bitunpack.bitUnpack((U8*) &res, sizeof(res)*8);
// ensure("U32->bitPack->bitUnpack->U32 should be equal", num == res);
// }
}

}

Loading