[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:
parent
df73fd6031
commit
552ffd38dc
@ -178,7 +178,6 @@ v8_source_set("cctest_sources") {
|
|||||||
"test-accessor-assembler.cc",
|
"test-accessor-assembler.cc",
|
||||||
"test-accessors.cc",
|
"test-accessors.cc",
|
||||||
"test-allocation.cc",
|
"test-allocation.cc",
|
||||||
"test-api-accessors.cc",
|
|
||||||
"test-api-array-buffer.cc",
|
"test-api-array-buffer.cc",
|
||||||
"test-api-icu.cc",
|
"test-api-icu.cc",
|
||||||
"test-api-interceptors.cc",
|
"test-api-interceptors.cc",
|
||||||
|
@ -210,6 +210,7 @@ v8_source_set("unittests_sources") {
|
|||||||
"../../testing/gmock-support.h",
|
"../../testing/gmock-support.h",
|
||||||
"../../testing/gtest-support.h",
|
"../../testing/gtest-support.h",
|
||||||
"api/access-check-unittest.cc",
|
"api/access-check-unittest.cc",
|
||||||
|
"api/accessor-unittest.cc",
|
||||||
"api/deserialize-unittest.cc",
|
"api/deserialize-unittest.cc",
|
||||||
"api/exception-unittest.cc",
|
"api/exception-unittest.cc",
|
||||||
"api/interceptor-unittest.cc",
|
"api/interceptor-unittest.cc",
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -9,6 +9,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "include/v8-isolate.h"
|
||||||
#include "testing/gmock/include/gmock/gmock.h"
|
#include "testing/gmock/include/gmock/gmock.h"
|
||||||
|
|
||||||
namespace testing {
|
namespace testing {
|
||||||
@ -72,6 +73,30 @@ MATCHER_P(BitEq, x, std::string(negation ? "isn't" : "is") +
|
|||||||
return std::memcmp(&arg, &x, sizeof(x)) == 0;
|
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
|
// 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.
|
// is unset, and once set, compares the value for equality with the argument.
|
||||||
|
Loading…
Reference in New Issue
Block a user