• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "test_utils.h"
17 
18 #include <iomanip>
19 #include <sstream>
20 
21 #include <base/containers/string.h>
22 
23 namespace BASE_NS {
24 
operator <<(std::ostream & os,const BASE_NS::Uid & uid)25 std::ostream& operator<<(std::ostream& os, const BASE_NS::Uid& uid)
26 {
27     std::stringstream ss;
28 
29     ss << "{" << std::setfill('0') << std::setw(2) << std::hex; // 2: param
30     for (size_t i = 0; i < sizeof(uid.data); i++) {
31         ss << static_cast<uint16_t>(uid.data[i]);
32         if (i == 3 || i == 5 || i == 7 || i == 9) { // 3, 5, 7, 9: param
33             ss << "-";
34         }
35     }
36     ss << "}";
37     return os << ss.str();
38 }
39 
operator <<(std::ostream & os,const BASE_NS::string & s)40 std::ostream& operator<<(std::ostream& os, const BASE_NS::string& s)
41 {
42     return os << s.c_str();
43 }
44 
operator <<(std::ostream & os,const BASE_NS::string_view & s)45 std::ostream& operator<<(std::ostream& os, const BASE_NS::string_view& s)
46 {
47     return os << s.data();
48 }
49 
50 namespace Math {
51 
operator >(const BASE_NS::Math::Vec3 & lhs,const BASE_NS::Math::Vec3 & rhs)52 bool operator>(const BASE_NS::Math::Vec3& lhs, const BASE_NS::Math::Vec3& rhs)
53 {
54     return ((lhs.x > rhs.x) && (lhs.y > rhs.y));
55 }
56 
operator <(const BASE_NS::Math::Vec3 & lhs,const BASE_NS::Math::Vec3 & rhs)57 bool operator<(const BASE_NS::Math::Vec3& lhs, const BASE_NS::Math::Vec3& rhs)
58 {
59     return ((lhs.x < rhs.x) && (lhs.y < rhs.y));
60 }
61 
operator >(const BASE_NS::Math::Vec2 & lhs,const BASE_NS::Math::Vec2 & rhs)62 bool operator>(const BASE_NS::Math::Vec2& lhs, const BASE_NS::Math::Vec2& rhs)
63 {
64     return ((lhs.x > rhs.x) && (lhs.y > rhs.y));
65 }
66 
operator <(const BASE_NS::Math::Vec2 & lhs,const BASE_NS::Math::Vec2 & rhs)67 bool operator<(const BASE_NS::Math::Vec2& lhs, const BASE_NS::Math::Vec2& rhs)
68 {
69     return ((lhs.x < rhs.x) && (lhs.y < rhs.y));
70 }
71 
operator >=(const BASE_NS::Math::Vec3 & lhs,const BASE_NS::Math::Vec3 & rhs)72 bool operator>=(const BASE_NS::Math::Vec3& lhs, const BASE_NS::Math::Vec3& rhs)
73 {
74     return ((lhs.x >= rhs.x) && (lhs.y >= rhs.y));
75 }
76 
operator <=(const BASE_NS::Math::Vec3 & lhs,const BASE_NS::Math::Vec3 & rhs)77 bool operator<=(const BASE_NS::Math::Vec3& lhs, const BASE_NS::Math::Vec3& rhs)
78 {
79     return ((lhs.x <= rhs.x) && (lhs.y <= rhs.y));
80 }
81 
operator >=(const BASE_NS::Math::Vec2 & lhs,const BASE_NS::Math::Vec2 & rhs)82 bool operator>=(const BASE_NS::Math::Vec2& lhs, const BASE_NS::Math::Vec2& rhs)
83 {
84     return ((lhs.x >= rhs.x) && (lhs.y >= rhs.y));
85 }
86 
operator <=(const BASE_NS::Math::Vec2 & lhs,const BASE_NS::Math::Vec2 & rhs)87 bool operator<=(const BASE_NS::Math::Vec2& lhs, const BASE_NS::Math::Vec2& rhs)
88 {
89     return ((lhs.x <= rhs.x) && (lhs.y <= rhs.y));
90 }
91 
AreEqual(const BASE_NS::Math::Vec3 & lhs,const BASE_NS::Math::Vec3 & rhs,float epsilon)92 bool AreEqual(const BASE_NS::Math::Vec3& lhs, const BASE_NS::Math::Vec3& rhs, float epsilon)
93 {
94     return BASE_NS::Math::abs(lhs.x - rhs.x) < epsilon && BASE_NS::Math::abs(lhs.y - rhs.y) < epsilon &&
95            BASE_NS::Math::abs(lhs.z - rhs.z) < epsilon;
96 }
97 
AreNear(const BASE_NS::Math::Vec3 & lhs,const BASE_NS::Math::Vec3 & rhs)98 bool AreNear(const BASE_NS::Math::Vec3& lhs, const BASE_NS::Math::Vec3& rhs)
99 {
100     return AreEqual(lhs, rhs, 0.01f);
101 }
102 
AreEqual(const BASE_NS::Math::Vec2 & lhs,const BASE_NS::Math::Vec2 & rhs,float epsilon)103 bool AreEqual(const BASE_NS::Math::Vec2& lhs, const BASE_NS::Math::Vec2& rhs, float epsilon)
104 {
105     return BASE_NS::Math::abs(lhs.x - rhs.x) < epsilon && BASE_NS::Math::abs(lhs.y - rhs.y) < epsilon;
106 }
107 
AreNear(const BASE_NS::Math::Vec2 & lhs,const BASE_NS::Math::Vec2 & rhs)108 bool AreNear(const BASE_NS::Math::Vec2& lhs, const BASE_NS::Math::Vec2& rhs)
109 {
110     return AreEqual(lhs, rhs, 0.01f);
111 }
112 
operator <<(std::ostream & os,const BASE_NS::Math::Vec3 & vec)113 std::ostream& operator<<(std::ostream& os, const BASE_NS::Math::Vec3& vec)
114 {
115     std::stringstream ss;
116     ss << std::setprecision(6) << "BASE_NS::Math::Vec3 {" << vec.x << ", " << vec.y << ", " << vec.z << "}"; // 6: param
117     return os << ss.str();
118 }
119 
operator <<(std::ostream & os,const BASE_NS::Math::Vec2 & vec)120 std::ostream& operator<<(std::ostream& os, const BASE_NS::Math::Vec2& vec)
121 {
122     std::stringstream ss;
123     ss << std::setprecision(6) << "BASE_NS::Math::Vec2 {" << vec.x << ", " << vec.y << "}"; // 6: param
124     return os << ss.str();
125 }
126 
127 } // namespace Math
128 } // namespace BASE_NS
129 
130 namespace META_NS {
operator <<(std::ostream & os,const META_NS::TimeSpan & ts)131 std::ostream& operator<<(std::ostream& os, const META_NS::TimeSpan& ts)
132 {
133     return os << ts.ToMicroseconds() << "us";
134 }
135 
136 } // namespace META_NS
137