/src/mozilla-central/xpcom/rust/gtest/nsstring/Test.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | #include "gtest/gtest.h" |
2 | | #include <stdint.h> |
3 | | #include "nsString.h" |
4 | | |
5 | | extern "C" { |
6 | | // This function is called by the rust code in test.rs if a non-fatal test |
7 | | // failure occurs. |
8 | 0 | void GTest_ExpectFailure(const char* aMessage) { |
9 | 0 | EXPECT_STREQ(aMessage, ""); |
10 | 0 | } |
11 | | } |
12 | | |
13 | | #define SIZE_ALIGN_CHECK(Clazz) \ |
14 | | extern "C" void Rust_Test_ReprSizeAlign_##Clazz(size_t* size, size_t* align); \ |
15 | 0 | TEST(RustNsString, ReprSizeAlign_##Clazz) { \ |
16 | 0 | size_t size, align; \ |
17 | 0 | Rust_Test_ReprSizeAlign_##Clazz(&size, &align); \ |
18 | 0 | EXPECT_EQ(size, sizeof(Clazz)); \ |
19 | 0 | EXPECT_EQ(align, alignof(Clazz)); \ |
20 | 0 | } Unexecuted instantiation: RustNsString_ReprSizeAlign_nsString_Test::TestBody() Unexecuted instantiation: RustNsString_ReprSizeAlign_nsCString_Test::TestBody() |
21 | | |
22 | | SIZE_ALIGN_CHECK(nsString) |
23 | | SIZE_ALIGN_CHECK(nsCString) |
24 | | |
25 | | #define MEMBER_CHECK(Clazz, Member) \ |
26 | | extern "C" void Rust_Test_Member_##Clazz##_##Member(size_t* size, \ |
27 | | size_t* align, \ |
28 | | size_t* offset); \ |
29 | 0 | TEST(RustNsString, ReprMember_##Clazz##_##Member) { \ |
30 | 0 | class Hack : public Clazz { \ |
31 | 0 | public: \ |
32 | 0 | static void RunTest() { \ |
33 | 0 | size_t size, align, offset; \ |
34 | 0 | Rust_Test_Member_##Clazz##_##Member(&size, &align, &offset); \ |
35 | 0 | EXPECT_EQ(size, sizeof(mozilla::DeclVal<Hack>().Member)); \ |
36 | 0 | EXPECT_EQ(align, alignof(decltype(mozilla::DeclVal<Hack>().Member))); \ |
37 | 0 | EXPECT_EQ(offset, offsetof(Hack, Member)); \ |
38 | 0 | } \ Unexecuted instantiation: Unified_cpp_xpcom_rust_gtest0.cpp:RustNsString_ReprMember_nsString_mData_Test::TestBody()::Hack::RunTest() Unexecuted instantiation: Unified_cpp_xpcom_rust_gtest0.cpp:RustNsString_ReprMember_nsString_mLength_Test::TestBody()::Hack::RunTest() Unexecuted instantiation: Unified_cpp_xpcom_rust_gtest0.cpp:RustNsString_ReprMember_nsString_mDataFlags_Test::TestBody()::Hack::RunTest() Unexecuted instantiation: Unified_cpp_xpcom_rust_gtest0.cpp:RustNsString_ReprMember_nsString_mClassFlags_Test::TestBody()::Hack::RunTest() Unexecuted instantiation: Unified_cpp_xpcom_rust_gtest0.cpp:RustNsString_ReprMember_nsCString_mData_Test::TestBody()::Hack::RunTest() Unexecuted instantiation: Unified_cpp_xpcom_rust_gtest0.cpp:RustNsString_ReprMember_nsCString_mLength_Test::TestBody()::Hack::RunTest() Unexecuted instantiation: Unified_cpp_xpcom_rust_gtest0.cpp:RustNsString_ReprMember_nsCString_mDataFlags_Test::TestBody()::Hack::RunTest() Unexecuted instantiation: Unified_cpp_xpcom_rust_gtest0.cpp:RustNsString_ReprMember_nsCString_mClassFlags_Test::TestBody()::Hack::RunTest() |
39 | 0 | }; \ |
40 | 0 | static_assert(sizeof(Clazz) == sizeof(Hack), "Hack matches class"); \ |
41 | 0 | Hack::RunTest(); \ |
42 | 0 | } Unexecuted instantiation: RustNsString_ReprMember_nsString_mData_Test::TestBody() Unexecuted instantiation: RustNsString_ReprMember_nsString_mLength_Test::TestBody() Unexecuted instantiation: RustNsString_ReprMember_nsString_mDataFlags_Test::TestBody() Unexecuted instantiation: RustNsString_ReprMember_nsString_mClassFlags_Test::TestBody() Unexecuted instantiation: RustNsString_ReprMember_nsCString_mData_Test::TestBody() Unexecuted instantiation: RustNsString_ReprMember_nsCString_mLength_Test::TestBody() Unexecuted instantiation: RustNsString_ReprMember_nsCString_mDataFlags_Test::TestBody() Unexecuted instantiation: RustNsString_ReprMember_nsCString_mClassFlags_Test::TestBody() |
43 | | |
44 | | MEMBER_CHECK(nsString, mData) |
45 | | MEMBER_CHECK(nsString, mLength) |
46 | | MEMBER_CHECK(nsString, mDataFlags) |
47 | | MEMBER_CHECK(nsString, mClassFlags) |
48 | | MEMBER_CHECK(nsCString, mData) |
49 | | MEMBER_CHECK(nsCString, mLength) |
50 | | MEMBER_CHECK(nsCString, mDataFlags) |
51 | | MEMBER_CHECK(nsCString, mClassFlags) |
52 | | |
53 | | extern "C" void Rust_Test_NsStringFlags(uint16_t* f_terminated, |
54 | | uint16_t* f_voided, |
55 | | uint16_t* f_refcounted, |
56 | | uint16_t* f_owned, |
57 | | uint16_t* f_inline, |
58 | | uint16_t* f_literal, |
59 | | uint16_t* f_class_inline, |
60 | | uint16_t* f_class_null_terminated); |
61 | 0 | TEST(RustNsString, NsStringFlags) { |
62 | 0 | uint16_t f_terminated, f_voided, f_refcounted, f_owned, f_inline, f_literal, |
63 | 0 | f_class_inline, f_class_null_terminated; |
64 | 0 | Rust_Test_NsStringFlags(&f_terminated, |
65 | 0 | &f_voided, &f_refcounted, |
66 | 0 | &f_owned, &f_inline, |
67 | 0 | &f_literal, &f_class_inline, &f_class_null_terminated); |
68 | 0 | EXPECT_EQ(f_terminated, uint16_t(nsAString::DataFlags::TERMINATED)); |
69 | 0 | EXPECT_EQ(f_terminated, uint16_t(nsACString::DataFlags::TERMINATED)); |
70 | 0 | EXPECT_EQ(f_voided, uint16_t(nsAString::DataFlags::VOIDED)); |
71 | 0 | EXPECT_EQ(f_voided, uint16_t(nsACString::DataFlags::VOIDED)); |
72 | 0 | EXPECT_EQ(f_refcounted, uint16_t(nsAString::DataFlags::REFCOUNTED)); |
73 | 0 | EXPECT_EQ(f_refcounted, uint16_t(nsACString::DataFlags::REFCOUNTED)); |
74 | 0 | EXPECT_EQ(f_owned, uint16_t(nsAString::DataFlags::OWNED)); |
75 | 0 | EXPECT_EQ(f_owned, uint16_t(nsACString::DataFlags::OWNED)); |
76 | 0 | EXPECT_EQ(f_inline, uint16_t(nsAString::DataFlags::INLINE)); |
77 | 0 | EXPECT_EQ(f_inline, uint16_t(nsACString::DataFlags::INLINE)); |
78 | 0 | EXPECT_EQ(f_literal, uint16_t(nsAString::DataFlags::LITERAL)); |
79 | 0 | EXPECT_EQ(f_literal, uint16_t(nsACString::DataFlags::LITERAL)); |
80 | 0 | EXPECT_EQ(f_class_inline, uint16_t(nsAString::ClassFlags::INLINE)); |
81 | 0 | EXPECT_EQ(f_class_inline, uint16_t(nsACString::ClassFlags::INLINE)); |
82 | 0 | EXPECT_EQ(f_class_null_terminated, uint16_t(nsAString::ClassFlags::NULL_TERMINATED)); |
83 | 0 | EXPECT_EQ(f_class_null_terminated, uint16_t(nsACString::ClassFlags::NULL_TERMINATED)); |
84 | 0 | } |
85 | | |
86 | | extern "C" void Rust_StringFromCpp(const nsACString* aCStr, const nsAString* aStr); |
87 | 0 | TEST(RustNsString, StringFromCpp) { |
88 | 0 | nsAutoCString foo; |
89 | 0 | foo.AssignASCII("Hello, World!"); |
90 | 0 |
|
91 | 0 | nsAutoString bar; |
92 | 0 | bar.AssignASCII("Hello, World!"); |
93 | 0 |
|
94 | 0 | Rust_StringFromCpp(&foo, &bar); |
95 | 0 | } |
96 | | |
97 | | extern "C" void Rust_AssignFromRust(nsACString* aCStr, nsAString* aStr); |
98 | 0 | TEST(RustNsString, AssignFromRust) { |
99 | 0 | nsAutoCString cs; |
100 | 0 | nsAutoString s; |
101 | 0 | Rust_AssignFromRust(&cs, &s); |
102 | 0 | EXPECT_TRUE(cs.EqualsASCII("Hello, World!")); |
103 | 0 | EXPECT_TRUE(s.EqualsASCII("Hello, World!")); |
104 | 0 | } |
105 | | |
106 | | extern "C" { |
107 | 0 | void Cpp_AssignFromCpp(nsACString* aCStr, nsAString* aStr) { |
108 | 0 | aCStr->AssignASCII("Hello, World!"); |
109 | 0 | aStr->AssignASCII("Hello, World!"); |
110 | 0 | } |
111 | | } |
112 | | extern "C" void Rust_AssignFromCpp(); |
113 | 0 | TEST(RustNsString, AssignFromCpp) { |
114 | 0 | Rust_AssignFromCpp(); |
115 | 0 | } |
116 | | |
117 | | extern "C" void Rust_StringWrite(); |
118 | 0 | TEST(RustNsString, StringWrite) { |
119 | 0 | Rust_StringWrite(); |
120 | 0 | } |
121 | | |
122 | | extern "C" void Rust_FromEmptyRustString(); |
123 | 0 | TEST(RustNsString, FromEmptyRustString) { |
124 | 0 | Rust_FromEmptyRustString(); |
125 | 0 | } |
126 | | |
127 | | extern "C" void Rust_WriteToBufferFromRust(nsACString* aCStr, nsAString* aStr, nsACString* aFallibleCStr, nsAString* aFallibleStr); |
128 | 0 | TEST(RustNsString, WriteToBufferFromRust) { |
129 | 0 | nsAutoCString cStr; |
130 | 0 | nsAutoString str; |
131 | 0 | nsAutoCString fallibleCStr; |
132 | 0 | nsAutoString fallibleStr; |
133 | 0 |
|
134 | 0 | cStr.AssignLiteral("abc"); |
135 | 0 | str.AssignLiteral("abc"); |
136 | 0 | fallibleCStr.AssignLiteral("abc"); |
137 | 0 | fallibleStr.AssignLiteral("abc"); |
138 | 0 |
|
139 | 0 | Rust_WriteToBufferFromRust(&cStr, &str, &fallibleCStr, &fallibleStr); |
140 | 0 |
|
141 | 0 | EXPECT_TRUE(cStr.EqualsASCII("ABC")); |
142 | 0 | EXPECT_TRUE(str.EqualsASCII("ABC")); |
143 | 0 | EXPECT_TRUE(fallibleCStr.EqualsASCII("ABC")); |
144 | 0 | EXPECT_TRUE(fallibleStr.EqualsASCII("ABC")); |
145 | 0 | } |
146 | | |
147 | | extern "C" void Rust_InlineCapacityFromRust(const nsACString* aCStr, const nsAString* aStr, size_t* aCStrCapacity, size_t* aStrCapacity); |
148 | 0 | TEST(RustNsString, InlineCapacityFromRust) { |
149 | 0 | size_t cStrCapacity; |
150 | 0 | size_t strCapacity; |
151 | 0 | nsAutoCStringN<93> cs; |
152 | 0 | nsAutoStringN<93> s; |
153 | 0 | Rust_InlineCapacityFromRust(&cs, &s, &cStrCapacity, &strCapacity); |
154 | 0 | EXPECT_EQ(cStrCapacity, 92U); |
155 | 0 | EXPECT_EQ(strCapacity, 92U); |
156 | 0 | } |