openwebf/webf

macos test failure

calvinchengx opened this issue · 0 comments

Affected version

main

No same issues found.

  • Yes, I search all issues but not found.

Steps to Reproduce

On macos, run

npm run build:bridge:macos && node scripts/run_bridge_unit_test.js

Code example

In webf_test_env.cc, we clearly see that there are 5 mocked dart methods registered in our test environment.

void TEST_mockTestEnvDartMethods(void* testContext, OnJSError onJSError) {
  std::vector<uint64_t> mockMethods{
      reinterpret_cast<uint64_t>(onJSError),
      reinterpret_cast<uint64_t>(TEST_onMatchImageSnapshot),
      reinterpret_cast<uint64_t>(TEST_environment),
      reinterpret_cast<uint64_t>(TEST_simulatePointer),
      reinterpret_cast<uint64_t>(TEST_simulateInputText),
  };

  registerTestEnvDartMethods(testContext, mockMethods.data(), mockMethods.size());
}

It is missing the TEST_onMatchImageSnapshotBytes.

So we expect the dart native methods count to be 5.

In our test itself, in webf_test_context.cc, there are 6 C++ methods.

void WebFTestContext::registerTestEnvDartMethods(uint64_t* methodBytes, int32_t length) {
  size_t i = 0;

  auto& dartMethodPtr = context_->dartMethodPtr();

  dartMethodPtr->onJsError = reinterpret_cast<OnJSError>(methodBytes[i++]);
  dartMethodPtr->matchImageSnapshot = reinterpret_cast<MatchImageSnapshot>(methodBytes[i++]);
  dartMethodPtr->matchImageSnapshotBytes = reinterpret_cast<MatchImageSnapshotBytes>(methodBytes[i++]);
  dartMethodPtr->environment = reinterpret_cast<Environment>(methodBytes[i++]);
  dartMethodPtr->simulatePointer = reinterpret_cast<SimulatePointer>(methodBytes[i++]);
  dartMethodPtr->simulateInputText = reinterpret_cast<SimulateInputText>(methodBytes[i++]);

  assert_m(i == length, "Dart native methods count is not equal with C++ side method registrations.");
}

The assertion is supposed to be "Dart native methods count is not equal with C++ side method registrations.".

So,

(a) are trying to prove that the dart native methods count is really not equal with C++ side method registrations? If so, we should be asserting that i != length.

or

(b) are we trying to prove that the dart native methods count equals the C++ method registrations? I so, we should be registering the missing TEST_onMatchImageSnapshotBytes mock method and keep the assertion as i == length.

Doing (a) or (b), depending on what we are really trying to assert in our test, will allow our test to pass.

Let me know what we are trying to do in this test?
I will make the pull request accordingly.

Expected results

Tests should pass

Actual results

Assertion failed: (((void)"Dart native methods count is not equal with C++ side method registrations.", i == length)), function registerTestEnvDartMethods, file webf_test_context.cc, line 374.