TestSourceLocation.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright (c) 2021, Andrew Kaster <akaster@serenityos.org>
  3. * Copyright (c) 2021, Brian Gianforcaro <bgianf@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #include <LibTest/TestCase.h>
  8. #include <AK/SourceLocation.h>
  9. #include <AK/StringView.h>
  10. TEST_CASE(basic_scenario)
  11. {
  12. auto location = SourceLocation::current();
  13. EXPECT_EQ(__LINE__ - 1u, location.line_number());
  14. // Obviously not the prettiest way.
  15. StringView function { __FUNCTION__, strlen(__FUNCTION__) };
  16. StringView file { __FILE__, strlen(__FILE__) };
  17. EXPECT_EQ(function, location.function_name());
  18. EXPECT_EQ(file, location.filename());
  19. }
  20. static StringView test_default_arg(SourceLocation const& loc = SourceLocation::current())
  21. {
  22. return loc.function_name();
  23. }
  24. TEST_CASE(default_arg_scenario)
  25. {
  26. auto actual_calling_function = test_default_arg();
  27. auto expected_calling_function = StringView { __FUNCTION__, strlen(__FUNCTION__) };
  28. EXPECT_EQ(expected_calling_function, actual_calling_function);
  29. }