|
| 1 | +// Copyright (c) 2025 OPEN CASCADE SAS |
| 2 | +// |
| 3 | +// This file is part of Open CASCADE Technology software library. |
| 4 | +// |
| 5 | +// This library is free software; you can redistribute it and/or modify it under |
| 6 | +// the terms of the GNU Lesser General Public License version 2.1 as published |
| 7 | +// by the Free Software Foundation, with special exception defined in the file |
| 8 | +// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
| 9 | +// distribution for complete text of the license and disclaimer of any warranty. |
| 10 | +// |
| 11 | +// Alternatively, this file may be used under the terms of Open CASCADE |
| 12 | +// commercial license or contractual agreement. |
| 13 | + |
| 14 | +#include <gtest/gtest.h> |
| 15 | + |
| 16 | +#include <Graphic3d_ZLayerSettings.hxx> |
| 17 | + |
| 18 | +#include <sstream> |
| 19 | + |
| 20 | +//================================================================================================== |
| 21 | +// Default Constructor Tests |
| 22 | +//================================================================================================== |
| 23 | + |
| 24 | +TEST(Graphic3d_ZLayerSettingsTest, DefaultConstructor_IsVisibleTrue) |
| 25 | +{ |
| 26 | + Graphic3d_ZLayerSettings aSettings; |
| 27 | + EXPECT_TRUE(aSettings.IsVisible()) << "Default visibility should be TRUE"; |
| 28 | +} |
| 29 | + |
| 30 | +TEST(Graphic3d_ZLayerSettingsTest, DefaultConstructor_IsImmediateFalse) |
| 31 | +{ |
| 32 | + Graphic3d_ZLayerSettings aSettings; |
| 33 | + EXPECT_FALSE(aSettings.IsImmediate()) << "Default IsImmediate should be FALSE"; |
| 34 | +} |
| 35 | + |
| 36 | +TEST(Graphic3d_ZLayerSettingsTest, DefaultConstructor_IsRaytracableTrue) |
| 37 | +{ |
| 38 | + Graphic3d_ZLayerSettings aSettings; |
| 39 | + EXPECT_TRUE(aSettings.IsRaytracable()) << "Default IsRaytracable should be TRUE"; |
| 40 | +} |
| 41 | + |
| 42 | +TEST(Graphic3d_ZLayerSettingsTest, DefaultConstructor_DepthTestEnabled) |
| 43 | +{ |
| 44 | + Graphic3d_ZLayerSettings aSettings; |
| 45 | + EXPECT_TRUE(aSettings.ToEnableDepthTest()) << "Default depth test should be enabled"; |
| 46 | +} |
| 47 | + |
| 48 | +TEST(Graphic3d_ZLayerSettingsTest, DefaultConstructor_DepthWriteEnabled) |
| 49 | +{ |
| 50 | + Graphic3d_ZLayerSettings aSettings; |
| 51 | + EXPECT_TRUE(aSettings.ToEnableDepthWrite()) << "Default depth write should be enabled"; |
| 52 | +} |
| 53 | + |
| 54 | +//================================================================================================== |
| 55 | +// Visibility Tests |
| 56 | +//================================================================================================== |
| 57 | + |
| 58 | +TEST(Graphic3d_ZLayerSettingsTest, SetVisible_False) |
| 59 | +{ |
| 60 | + Graphic3d_ZLayerSettings aSettings; |
| 61 | + aSettings.SetVisible(Standard_False); |
| 62 | + EXPECT_FALSE(aSettings.IsVisible()) << "Visibility should be FALSE after SetVisible(false)"; |
| 63 | +} |
| 64 | + |
| 65 | +TEST(Graphic3d_ZLayerSettingsTest, SetVisible_True) |
| 66 | +{ |
| 67 | + Graphic3d_ZLayerSettings aSettings; |
| 68 | + aSettings.SetVisible(Standard_False); |
| 69 | + aSettings.SetVisible(Standard_True); |
| 70 | + EXPECT_TRUE(aSettings.IsVisible()) << "Visibility should be TRUE after SetVisible(true)"; |
| 71 | +} |
| 72 | + |
| 73 | +TEST(Graphic3d_ZLayerSettingsTest, SetVisible_Toggle) |
| 74 | +{ |
| 75 | + Graphic3d_ZLayerSettings aSettings; |
| 76 | + |
| 77 | + // Initially visible |
| 78 | + EXPECT_TRUE(aSettings.IsVisible()); |
| 79 | + |
| 80 | + // Hide |
| 81 | + aSettings.SetVisible(Standard_False); |
| 82 | + EXPECT_FALSE(aSettings.IsVisible()); |
| 83 | + |
| 84 | + // Show again |
| 85 | + aSettings.SetVisible(Standard_True); |
| 86 | + EXPECT_TRUE(aSettings.IsVisible()); |
| 87 | + |
| 88 | + // Hide again |
| 89 | + aSettings.SetVisible(Standard_False); |
| 90 | + EXPECT_FALSE(aSettings.IsVisible()); |
| 91 | +} |
| 92 | + |
| 93 | +//================================================================================================== |
| 94 | +// Other Property Tests |
| 95 | +//================================================================================================== |
| 96 | + |
| 97 | +TEST(Graphic3d_ZLayerSettingsTest, SetName) |
| 98 | +{ |
| 99 | + Graphic3d_ZLayerSettings aSettings; |
| 100 | + aSettings.SetName("TestLayer"); |
| 101 | + EXPECT_STREQ("TestLayer", aSettings.Name().ToCString()) << "Name should match set value"; |
| 102 | +} |
| 103 | + |
| 104 | +TEST(Graphic3d_ZLayerSettingsTest, SetImmediate) |
| 105 | +{ |
| 106 | + Graphic3d_ZLayerSettings aSettings; |
| 107 | + aSettings.SetImmediate(Standard_True); |
| 108 | + EXPECT_TRUE(aSettings.IsImmediate()) << "IsImmediate should be TRUE after SetImmediate(true)"; |
| 109 | +} |
| 110 | + |
| 111 | +TEST(Graphic3d_ZLayerSettingsTest, SetRaytracable) |
| 112 | +{ |
| 113 | + Graphic3d_ZLayerSettings aSettings; |
| 114 | + aSettings.SetRaytracable(Standard_False); |
| 115 | + EXPECT_FALSE(aSettings.IsRaytracable()) |
| 116 | + << "IsRaytracable should be FALSE after SetRaytracable(false)"; |
| 117 | +} |
| 118 | + |
| 119 | +TEST(Graphic3d_ZLayerSettingsTest, SetEnableDepthTest) |
| 120 | +{ |
| 121 | + Graphic3d_ZLayerSettings aSettings; |
| 122 | + aSettings.SetEnableDepthTest(Standard_False); |
| 123 | + EXPECT_FALSE(aSettings.ToEnableDepthTest()) |
| 124 | + << "Depth test should be disabled after SetEnableDepthTest(false)"; |
| 125 | +} |
| 126 | + |
| 127 | +TEST(Graphic3d_ZLayerSettingsTest, SetEnableDepthWrite) |
| 128 | +{ |
| 129 | + Graphic3d_ZLayerSettings aSettings; |
| 130 | + aSettings.SetEnableDepthWrite(Standard_False); |
| 131 | + EXPECT_FALSE(aSettings.ToEnableDepthWrite()) |
| 132 | + << "Depth write should be disabled after SetEnableDepthWrite(false)"; |
| 133 | +} |
| 134 | + |
| 135 | +//================================================================================================== |
| 136 | +// DumpJson Tests |
| 137 | +//================================================================================================== |
| 138 | + |
| 139 | +TEST(Graphic3d_ZLayerSettingsTest, DumpJson_ContainsVisibility) |
| 140 | +{ |
| 141 | + Graphic3d_ZLayerSettings aSettings; |
| 142 | + aSettings.SetVisible(Standard_True); |
| 143 | + |
| 144 | + std::ostringstream aStream; |
| 145 | + aSettings.DumpJson(aStream); |
| 146 | + |
| 147 | + const std::string aJsonStr = aStream.str(); |
| 148 | + // Note: DumpFieldToName strips the "my" prefix, so "myVisible" becomes "Visible" |
| 149 | + EXPECT_NE(std::string::npos, aJsonStr.find("Visible")) << "DumpJson should contain Visible field"; |
| 150 | +} |
| 151 | + |
| 152 | +TEST(Graphic3d_ZLayerSettingsTest, DumpJson_VisibilityValueTrue) |
| 153 | +{ |
| 154 | + Graphic3d_ZLayerSettings aSettings; |
| 155 | + aSettings.SetVisible(Standard_True); |
| 156 | + |
| 157 | + std::ostringstream aStream; |
| 158 | + aSettings.DumpJson(aStream); |
| 159 | + |
| 160 | + const std::string aJsonStr = aStream.str(); |
| 161 | + // Check that Visible appears with value 1 (true) |
| 162 | + // Note: DumpFieldToName strips the "my" prefix |
| 163 | + EXPECT_NE(std::string::npos, aJsonStr.find("\"Visible\": 1")) |
| 164 | + << "DumpJson should contain Visible: 1 when visible"; |
| 165 | +} |
| 166 | + |
| 167 | +TEST(Graphic3d_ZLayerSettingsTest, DumpJson_VisibilityValueFalse) |
| 168 | +{ |
| 169 | + Graphic3d_ZLayerSettings aSettings; |
| 170 | + aSettings.SetVisible(Standard_False); |
| 171 | + |
| 172 | + std::ostringstream aStream; |
| 173 | + aSettings.DumpJson(aStream); |
| 174 | + |
| 175 | + const std::string aJsonStr = aStream.str(); |
| 176 | + // Note: DumpFieldToName strips the "my" prefix |
| 177 | + EXPECT_NE(std::string::npos, aJsonStr.find("\"Visible\": 0")) |
| 178 | + << "DumpJson should contain Visible: 0 when hidden"; |
| 179 | +} |
0 commit comments