Commit 552ffd38 authored by jameslahm's avatar jameslahm Committed by V8 LUCI CQ

[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/+/3593573Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80577}
parent df73fd60
......@@ -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",
......
......@@ -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",
......
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment