Skip to content
Merged
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
37 changes: 37 additions & 0 deletions Sources/Tests/CPPWrapperUnitTests/tests/RunTests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <AngouriMath.h>
#include <gtest/gtest.h>
#include <vector>

TEST(RunTests, ParsingTest1) {
auto src = "x / 2 + 3";
Expand Down Expand Up @@ -174,3 +175,39 @@ TEST(RunTests, ToComplex) {
EXPECT_EQ(6.0, com.real());
EXPECT_EQ(1.0, com.imag());
}

// A method called on a temporary Entity threw NonExistentObjectAddressingException: the
// temporary was destroyed, and its handle released, before the call that used it returned.
// https://github.com/asc-community/AngouriMath/issues/367
//
// It does not reproduce on this version. The issue's own line is first, then the shapes a
// too-early release would show up in and this one did not: a result outliving the temporary
// it came from, two calls chained off one, a temporary passed as an argument, a result
// copied out of the scope that made it, and enough repetitions to shake loose a handle that
// is freed but not yet reused.
TEST(RunTests, TemporaryEntityOutlivesTheCallOnIt) {
EXPECT_EQ(AngouriMath::Entity("x + 2").Simplify().ToString(), "2 + x");
}

TEST(RunTests, ResultOutlivesTheTemporaryItCameFrom) {
auto simplified = AngouriMath::Entity("x + 2").Simplify();
EXPECT_EQ(simplified.ToString(), "2 + x");
}

TEST(RunTests, TwoCallsChainedOffOneTemporary) {
EXPECT_EQ(AngouriMath::Entity("(x + 2) * 1").Simplify().Differentiate("x").ToString(), "1");
}

TEST(RunTests, ResultCopiedOutOfTheScopeThatMadeIt) {
std::vector<AngouriMath::Entity> kept;
{
kept.push_back(AngouriMath::Entity("sin(x) ^ 2 + cos(x) ^ 2").Simplify());
}
EXPECT_EQ(kept[0].ToString(), "1");
}

TEST(RunTests, ManyTemporariesDoNotReleaseAHandleInUse) {
for (int i = 0; i < 200; i++) {
EXPECT_EQ(AngouriMath::Entity("x + 2").Simplify().ToString(), "2 + x");
}
}
Loading