[test] Migrate cctest/test-api-accessors.cc to unittests/

... api/accessor-unittest.cc.

- Add IsInt32, IsString, IsUndefined matcher in
testing/gmock-support.h.

Bug: v8:12781
Change-Id: I764491d7643e35fb8bc1621e857873aa24f64ccd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3593573
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80577}
This commit is contained in:
jameslahm 2022-05-17 09:24:27 +08:00 committed by V8 LUCI CQ
parent df73fd6031
commit 552ffd38dc
4 changed files with 319 additions and 306 deletions

View File

@ -178,7 +178,6 @@ v8_source_set("cctest_sources") {
"test-accessor-assembler.cc",
"test-accessors.cc",
"test-allocation.cc",
"test-api-accessors.cc",
"test-api-array-buffer.cc",
"test-api-icu.cc",
"test-api-interceptors.cc",

View File

@ -210,6 +210,7 @@ v8_source_set("unittests_sources") {
"../../testing/gmock-support.h",
"../../testing/gtest-support.h",
"api/access-check-unittest.cc",
"api/accessor-unittest.cc",
"api/deserialize-unittest.cc",
"api/exception-unittest.cc",
"api/interceptor-unittest.cc",

View File

@ -9,6 +9,7 @@
#include <cstring>
#include <string>
#include "include/v8-isolate.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace testing {
@ -72,6 +73,30 @@ MATCHER_P(BitEq, x, std::string(negation ? "isn't" : "is") +
return std::memcmp(&arg, &x, sizeof(x)) == 0;
}
// Creates a polymorphic matcher that matches JSValue to Int32.
MATCHER_P(IsInt32, expected,
std::string(negation ? "isn't" : "is") + " Int32 " +
PrintToString(expected)) {
return arg->IsInt32() &&
arg->Int32Value(v8::Isolate::GetCurrent()->GetCurrentContext())
.FromJust() == expected;
}
// Creates a polymorphic matcher that matches JSValue to String.
MATCHER_P(IsString, expected,
std::string(negation ? "isn't" : "is") + " String " +
PrintToString(expected)) {
if (!arg->IsString()) {
return false;
}
v8::String::Utf8Value utf8(v8::Isolate::GetCurrent(), arg);
return strcmp(expected, *utf8) == 0;
}
// Creates a polymorphic matcher that matches JSValue to Undefined.
MATCHER(IsUndefined, std::string(negation ? "isn't" : "is") + " Undefined") {
return arg->IsUndefined();
}
// CaptureEq(capture) captures the value passed in during matching as long as it
// is unset, and once set, compares the value for equality with the argument.