From b0136ceedf66f1d93cd0a91d9e7958f6bc0e3121 Mon Sep 17 00:00:00 2001 From: whaffman Date: Mon, 6 Oct 2025 16:30:44 +0200 Subject: [PATCH] fixed some testws --- tests/config/test_directives.cpp | 15 ++++++----- webserv/config/validation/ConfigValidator.cpp | 1 + .../directive_rules/DirectiveRules.hpp | 5 ++++ .../structural_rules/StructuralRules.hpp | 27 ------------------- 4 files changed, 14 insertions(+), 34 deletions(-) create mode 100644 webserv/config/validation/directive_rules/DirectiveRules.hpp diff --git a/tests/config/test_directives.cpp b/tests/config/test_directives.cpp index 20431b0..985285a 100644 --- a/tests/config/test_directives.cpp +++ b/tests/config/test_directives.cpp @@ -38,7 +38,7 @@ TEST_F(DirectiveTest, StringDirectiveParse) StringDirective directive("root", ""); directive.parse("/var/www/html"); - EXPECT_EQ(directive.getValueAs(), "/var/www/html"); + EXPECT_EQ(directive.getValue().get(), "/var/www/html"); } TEST_F(DirectiveTest, IntDirectiveCreation) @@ -55,7 +55,7 @@ TEST_F(DirectiveTest, IntDirectiveParse) IntDirective directive("port", "0"); directive.parse("9000"); - EXPECT_EQ(directive.getValueAs(), 9000); + EXPECT_EQ(directive.getValue().get(), 9000); } TEST_F(DirectiveTest, BoolDirectiveCreation) @@ -72,16 +72,16 @@ TEST_F(DirectiveTest, BoolDirectiveParsing) BoolDirective directive("test", "off"); directive.parse("on"); - EXPECT_TRUE(directive.getValueAs()); + EXPECT_TRUE(directive.getValue().get()); directive.parse("off"); - EXPECT_FALSE(directive.getValueAs()); + EXPECT_FALSE(directive.getValue().get()); directive.parse("true"); - EXPECT_TRUE(directive.getValueAs()); + EXPECT_TRUE(directive.getValue().get()); directive.parse("false"); - EXPECT_FALSE(directive.getValueAs()); + EXPECT_FALSE(directive.getValue().get()); } TEST_F(DirectiveTest, DirectiveFactoryCreateStringDirective) @@ -90,7 +90,8 @@ TEST_F(DirectiveTest, DirectiveFactoryCreateStringDirective) ASSERT_NE(directive, nullptr); EXPECT_EQ(directive->getName(), "server_name"); - EXPECT_TRUE(directive->getValue().holds>()); + EXPECT_TRUE(directive->getValue().holds()); + EXPECT_EQ(directive->getValue().get(), "example.com"); } TEST_F(DirectiveTest, DirectiveFactoryCreateIntDirective) diff --git a/webserv/config/validation/ConfigValidator.cpp b/webserv/config/validation/ConfigValidator.cpp index 4e55128..80af27d 100644 --- a/webserv/config/validation/ConfigValidator.cpp +++ b/webserv/config/validation/ConfigValidator.cpp @@ -1,4 +1,5 @@ #include + #include // for ValidationEngine #include // for AValidationRule #include // for AllowedValuesRule diff --git a/webserv/config/validation/directive_rules/DirectiveRules.hpp b/webserv/config/validation/directive_rules/DirectiveRules.hpp new file mode 100644 index 0000000..2c3f8e1 --- /dev/null +++ b/webserv/config/validation/directive_rules/DirectiveRules.hpp @@ -0,0 +1,5 @@ +#include "webserv/config/validation/directive_rules/AValidationRule.hpp" + +#include "webserv/config/validation/directive_rules/AllowedValuesRule.hpp" +#include "webserv/config/validation/directive_rules/PortValidationRule.hpp" +#include "webserv/config/validation/directive_rules/RequiredDirectiveRule.hpp" \ No newline at end of file diff --git a/webserv/config/validation/structural_rules/StructuralRules.hpp b/webserv/config/validation/structural_rules/StructuralRules.hpp index 0c68b0e..be9bb1e 100644 --- a/webserv/config/validation/structural_rules/StructuralRules.hpp +++ b/webserv/config/validation/structural_rules/StructuralRules.hpp @@ -7,30 +7,3 @@ #include "webserv/config/validation/structural_rules/MinimumServerBlocksRule.hpp" #include "webserv/config/validation/structural_rules/RequiredLocationBlocksRule.hpp" #include "webserv/config/validation/structural_rules/UniqueServerNamesRule.hpp" - -/** - * Structural Validation Rules for WebServ Configuration - * - * These rules validate the overall structure and relationships - * between configuration blocks, rather than individual directive values. - * - * Available Rules: - * - * 1. MinimumServerBlocksRule - Ensures global config has minimum number of server blocks - * 2. RequiredLocationBlocksRule - Ensures each server has minimum number of location blocks - * 3. UniqueServerNamesRule - Ensures all server names are unique across configuration - * - * Usage: - * - * // In ValidationEngine setup - * engine.addStructuralRule(std::make_unique(1)); - * engine.addStructuralRule(std::make_unique(1)); - * engine.addStructuralRule(std::make_unique()); - * - * Each rule inherits from AStructuralValidationRule and can validate at: - * - Global level (validateGlobal) - * - Server level (validateServer) - * - Location level (validateLocation) - * - * Rules have descriptive names and descriptions set in their constructors. - */ \ No newline at end of file