18bf80f4bSopenharmony_ci/*
28bf80f4bSopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd.
38bf80f4bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
48bf80f4bSopenharmony_ci * you may not use this file except in compliance with the License.
58bf80f4bSopenharmony_ci * You may obtain a copy of the License at
68bf80f4bSopenharmony_ci *
78bf80f4bSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
88bf80f4bSopenharmony_ci *
98bf80f4bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
108bf80f4bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
118bf80f4bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128bf80f4bSopenharmony_ci * See the License for the specific language governing permissions and
138bf80f4bSopenharmony_ci * limitations under the License.
148bf80f4bSopenharmony_ci */
158bf80f4bSopenharmony_ci
168bf80f4bSopenharmony_ci#include <iomanip>
178bf80f4bSopenharmony_ci#include <sstream>
188bf80f4bSopenharmony_ci
198bf80f4bSopenharmony_ci#include <base/containers/string.h>
208bf80f4bSopenharmony_ci
218bf80f4bSopenharmony_ci#include "test_utils.h"
228bf80f4bSopenharmony_ci
238bf80f4bSopenharmony_cinamespace {
248bf80f4bSopenharmony_ci    // The width of the output field
258bf80f4bSopenharmony_ci    const int TWO = 2;
268bf80f4bSopenharmony_ci
278bf80f4bSopenharmony_ci    // Insert '-' separator at a specific location
288bf80f4bSopenharmony_ci    const int THREE = 3;
298bf80f4bSopenharmony_ci    const int FIVE = 5;
308bf80f4bSopenharmony_ci    const int SEVEN = 7;
318bf80f4bSopenharmony_ci    const int NINE = 9;
328bf80f4bSopenharmony_ci
338bf80f4bSopenharmony_ci    // Floating-point precision
348bf80f4bSopenharmony_ci    const int SIX = 6;
358bf80f4bSopenharmony_ci}
368bf80f4bSopenharmony_ci
378bf80f4bSopenharmony_cinamespace BASE_NS {
388bf80f4bSopenharmony_cistd::ostream& operator<<(std::ostream& os, const BASE_NS::Uid& uid)
398bf80f4bSopenharmony_ci{
408bf80f4bSopenharmony_ci    std::stringstream ss;
418bf80f4bSopenharmony_ci    ss << "{" << std::setfill('0') << std::setw(TWO) << std::hex;
428bf80f4bSopenharmony_ci    for (size_t i = 0; i < sizeof(uid.data); i++) {
438bf80f4bSopenharmony_ci        ss << static_cast<uint16_t>(uid.data[i]);
448bf80f4bSopenharmony_ci        if (i == THREE || i == FIVE || i == SEVEN || i == NINE) {
458bf80f4bSopenharmony_ci            ss << "-";
468bf80f4bSopenharmony_ci        }
478bf80f4bSopenharmony_ci    }
488bf80f4bSopenharmony_ci    ss << "}";
498bf80f4bSopenharmony_ci    return os << ss.str();
508bf80f4bSopenharmony_ci}
518bf80f4bSopenharmony_ci
528bf80f4bSopenharmony_cistd::ostream& operator<<(std::ostream& os, const BASE_NS::string& s)
538bf80f4bSopenharmony_ci{
548bf80f4bSopenharmony_ci    return os << s.c_str();
558bf80f4bSopenharmony_ci}
568bf80f4bSopenharmony_ci
578bf80f4bSopenharmony_cistd::ostream& operator<<(std::ostream& os, const BASE_NS::string_view& s)
588bf80f4bSopenharmony_ci{
598bf80f4bSopenharmony_ci    return os << s.data();
608bf80f4bSopenharmony_ci}
618bf80f4bSopenharmony_ci
628bf80f4bSopenharmony_cinamespace Math {
638bf80f4bSopenharmony_cibool operator>(const BASE_NS::Math::Vec3& lhs, const BASE_NS::Math::Vec3& rhs)
648bf80f4bSopenharmony_ci{
658bf80f4bSopenharmony_ci    return ((lhs.x > rhs.x) && (lhs.y > rhs.y));
668bf80f4bSopenharmony_ci}
678bf80f4bSopenharmony_ci
688bf80f4bSopenharmony_cibool operator<(const BASE_NS::Math::Vec3& lhs, const BASE_NS::Math::Vec3& rhs)
698bf80f4bSopenharmony_ci{
708bf80f4bSopenharmony_ci    return ((lhs.x < rhs.x) && (lhs.y < rhs.y));
718bf80f4bSopenharmony_ci}
728bf80f4bSopenharmony_ci
738bf80f4bSopenharmony_cibool operator>(const BASE_NS::Math::Vec2& lhs, const BASE_NS::Math::Vec2& rhs)
748bf80f4bSopenharmony_ci{
758bf80f4bSopenharmony_ci    return ((lhs.x > rhs.x) && (lhs.y > rhs.y));
768bf80f4bSopenharmony_ci}
778bf80f4bSopenharmony_ci
788bf80f4bSopenharmony_cibool operator<(const BASE_NS::Math::Vec2& lhs, const BASE_NS::Math::Vec2& rhs)
798bf80f4bSopenharmony_ci{
808bf80f4bSopenharmony_ci    return ((lhs.x < rhs.x) && (lhs.y < rhs.y));
818bf80f4bSopenharmony_ci}
828bf80f4bSopenharmony_ci
838bf80f4bSopenharmony_cibool operator>=(const BASE_NS::Math::Vec3& lhs, const BASE_NS::Math::Vec3& rhs)
848bf80f4bSopenharmony_ci{
858bf80f4bSopenharmony_ci    return ((lhs.x >= rhs.x) && (lhs.y >= rhs.y));
868bf80f4bSopenharmony_ci}
878bf80f4bSopenharmony_ci
888bf80f4bSopenharmony_cibool operator<=(const BASE_NS::Math::Vec3& lhs, const BASE_NS::Math::Vec3& rhs)
898bf80f4bSopenharmony_ci{
908bf80f4bSopenharmony_ci    return ((lhs.x <= rhs.x) && (lhs.y <= rhs.y));
918bf80f4bSopenharmony_ci}
928bf80f4bSopenharmony_ci
938bf80f4bSopenharmony_cibool operator>=(const BASE_NS::Math::Vec2& lhs, const BASE_NS::Math::Vec2& rhs)
948bf80f4bSopenharmony_ci{
958bf80f4bSopenharmony_ci    return ((lhs.x >= rhs.x) && (lhs.y >= rhs.y));
968bf80f4bSopenharmony_ci}
978bf80f4bSopenharmony_ci
988bf80f4bSopenharmony_cibool operator<=(const BASE_NS::Math::Vec2& lhs, const BASE_NS::Math::Vec2& rhs)
998bf80f4bSopenharmony_ci{
1008bf80f4bSopenharmony_ci    return ((lhs.x <= rhs.x) && (lhs.y <= rhs.y));
1018bf80f4bSopenharmony_ci}
1028bf80f4bSopenharmony_ci
1038bf80f4bSopenharmony_cibool AreEqual(const BASE_NS::Math::Vec3& lhs, const BASE_NS::Math::Vec3& rhs, float epsilon)
1048bf80f4bSopenharmony_ci{
1058bf80f4bSopenharmony_ci    return BASE_NS::Math::abs(lhs.x - rhs.x) < epsilon && BASE_NS::Math::abs(lhs.y - rhs.y) < epsilon &&
1068bf80f4bSopenharmony_ci           BASE_NS::Math::abs(lhs.z - rhs.z) < epsilon;
1078bf80f4bSopenharmony_ci}
1088bf80f4bSopenharmony_ci
1098bf80f4bSopenharmony_cibool AreNear(const BASE_NS::Math::Vec3& lhs, const BASE_NS::Math::Vec3& rhs)
1108bf80f4bSopenharmony_ci{
1118bf80f4bSopenharmony_ci    return AreEqual(lhs, rhs, 0.01f);
1128bf80f4bSopenharmony_ci}
1138bf80f4bSopenharmony_ci
1148bf80f4bSopenharmony_cibool AreEqual(const BASE_NS::Math::Vec2& lhs, const BASE_NS::Math::Vec2& rhs, float epsilon)
1158bf80f4bSopenharmony_ci{
1168bf80f4bSopenharmony_ci    return BASE_NS::Math::abs(lhs.x - rhs.x) < epsilon && BASE_NS::Math::abs(lhs.y - rhs.y) < epsilon;
1178bf80f4bSopenharmony_ci}
1188bf80f4bSopenharmony_ci
1198bf80f4bSopenharmony_cibool AreNear(const BASE_NS::Math::Vec2& lhs, const BASE_NS::Math::Vec2& rhs)
1208bf80f4bSopenharmony_ci{
1218bf80f4bSopenharmony_ci    return AreEqual(lhs, rhs, 0.01f);
1228bf80f4bSopenharmony_ci}
1238bf80f4bSopenharmony_ci
1248bf80f4bSopenharmony_cistd::ostream& operator<<(std::ostream& os, const BASE_NS::Math::Vec3& vec)
1258bf80f4bSopenharmony_ci{
1268bf80f4bSopenharmony_ci    std::stringstream ss;
1278bf80f4bSopenharmony_ci    ss << std::setprecision(SIX) << "BASE_NS::Math::Vec3 {" << vec.x << ", " << vec.y << ", " << vec.z << "}";
1288bf80f4bSopenharmony_ci    return os << ss.str();
1298bf80f4bSopenharmony_ci}
1308bf80f4bSopenharmony_cistd::ostream& operator<<(std::ostream& os, const BASE_NS::Math::Vec2& vec)
1318bf80f4bSopenharmony_ci{
1328bf80f4bSopenharmony_ci    std::stringstream ss;
1338bf80f4bSopenharmony_ci    ss << std::setprecision(SIX) << "BASE_NS::Math::Vec2 {" << vec.x << ", " << vec.y << "}";
1348bf80f4bSopenharmony_ci    return os << ss.str();
1358bf80f4bSopenharmony_ci}
1368bf80f4bSopenharmony_ci
1378bf80f4bSopenharmony_ci} // namespace Math
1388bf80f4bSopenharmony_ci} // namespace BASE_NS
1398bf80f4bSopenharmony_ci
1408bf80f4bSopenharmony_cinamespace META_NS {
1418bf80f4bSopenharmony_ci
1428bf80f4bSopenharmony_cistd::ostream& operator<<(std::ostream& os, const META_NS::TimeSpan& ts)
1438bf80f4bSopenharmony_ci{
1448bf80f4bSopenharmony_ci    return os << ts.ToMicroseconds() << "us";
1458bf80f4bSopenharmony_ci}
1468bf80f4bSopenharmony_ci
1478bf80f4bSopenharmony_ci} // namespace META_NS