serenity/Tests/AK/TestFixedArray.cpp
creator1creeper1 3c05261611 AK+Everywhere: Make FixedArray OOM-safe
FixedArray now doesn't expose any infallible constructors anymore.
Rather, it exposes fallible methods. Therefore, it can be used for
OOM-safe code.
This commit also converts the rest of the system to use the new API.
However, as an example, VMObject can't take advantage of this yet,
as we would have to endow VMObject with a fallible static
construction method, which would require a very fundamental change
to VMObject's whole inheritance hierarchy.
2022-01-08 22:54:05 +01:00

30 lines
566 B
C++

/*
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibTest/TestSuite.h>
#include <AK/FixedArray.h>
#include <AK/String.h>
TEST_CASE(construct)
{
EXPECT(FixedArray<int>().size() == 0);
}
TEST_CASE(ints)
{
FixedArray<int> ints = FixedArray<int>::must_create_but_fixme_should_propagate_errors(3);
ints[0] = 0;
ints[1] = 1;
ints[2] = 2;
EXPECT_EQ(ints[0], 0);
EXPECT_EQ(ints[1], 1);
EXPECT_EQ(ints[2], 2);
ints.clear();
EXPECT_EQ(ints.size(), 0u);
}