2021-04-24 05:26:53 +00:00
|
|
|
/*
|
2021-05-30 13:28:59 +00:00
|
|
|
* Copyright (c) 2021, Andrew Kaster <akaster@serenityos.org>
|
2021-04-24 05:26:53 +00:00
|
|
|
* Copyright (c) 2021, Brian Gianforcaro <bgianf@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
2021-04-25 05:53:23 +00:00
|
|
|
#include <LibTest/TestCase.h>
|
|
|
|
|
2021-04-24 05:26:53 +00:00
|
|
|
#include <AK/SourceLocation.h>
|
|
|
|
#include <AK/StringView.h>
|
|
|
|
|
|
|
|
TEST_CASE(basic_scenario)
|
|
|
|
{
|
|
|
|
auto location = SourceLocation::current();
|
2022-07-11 20:29:31 +00:00
|
|
|
EXPECT_EQ(__LINE__ - 1u, location.line_number());
|
|
|
|
|
|
|
|
// Obviously not the prettiest way.
|
|
|
|
StringView function { __FUNCTION__, strlen(__FUNCTION__) };
|
|
|
|
StringView file { __FILE__, strlen(__FILE__) };
|
|
|
|
|
|
|
|
EXPECT_EQ(function, location.function_name());
|
|
|
|
EXPECT_EQ(file, location.filename());
|
2021-04-24 05:26:53 +00:00
|
|
|
}
|
|
|
|
|
2022-04-01 17:58:27 +00:00
|
|
|
static StringView test_default_arg(SourceLocation const& loc = SourceLocation::current())
|
2021-04-24 05:26:53 +00:00
|
|
|
{
|
|
|
|
return loc.function_name();
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE(default_arg_scenario)
|
|
|
|
{
|
|
|
|
auto actual_calling_function = test_default_arg();
|
2022-07-11 19:53:29 +00:00
|
|
|
auto expected_calling_function = StringView { __FUNCTION__, strlen(__FUNCTION__) };
|
2021-04-24 05:26:53 +00:00
|
|
|
|
|
|
|
EXPECT_EQ(expected_calling_function, actual_calling_function);
|
|
|
|
}
|