Exemple #1
0
    // Test for shouldLog() when we have configured a single component.
    // Also checks that severity level has been reverted to match LogComponent::kDefault
    // after clearing level.
    // Minimum severity levels:
    // LogComponent::kDefault: 1
    // componentA: 2
    TEST_F(LogTestUnadornedEncoder, LogComponentSettingsShouldLogSingleComponent) {
        LogComponentSettings settings;

        settings.setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Debug(1));
        settings.setMinimumLoggedSeverity(componentA, LogSeverity::Debug(2));

        // Components for log message: componentA only.
        ASSERT_TRUE(settings.shouldLog(componentA, LogSeverity::Debug(2)));
        ASSERT_FALSE(settings.shouldLog(componentA, LogSeverity::Debug(3)));

        // Clear severity level for componentA and check shouldLog() again.
        settings.clearMinimumLoggedSeverity(componentA);
        ASSERT_TRUE(settings.shouldLog(componentA, LogSeverity::Debug(1)));
        ASSERT_FALSE(settings.shouldLog(componentA, LogSeverity::Debug(2)));

        // Test shouldLog() with global settings.
        logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault,
                                                            LogSeverity::Debug(1));

        // Components for log message: LogComponent::kDefault only.
        ASSERT_TRUE(shouldLog(LogSeverity::Debug(1)));
        ASSERT_FALSE(shouldLog(LogSeverity::Debug(2)));

        logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault,
                                                            LogSeverity::Log());
    }
Exemple #2
0
    // Log component hierarchy.
    TEST_F(LogTestUnadornedEncoder, LogComponentHierarchy) {
        // Parent component is not meaningful for kDefault and kNumLogComponents.
        ASSERT_EQUALS(LogComponent::kNumLogComponents,
                      LogComponent(LogComponent::kDefault).parent());
        ASSERT_EQUALS(LogComponent::kNumLogComponents,
                      LogComponent(LogComponent::kNumLogComponents).parent());

        // Default -> ComponentD -> ComponentE
        ASSERT_EQUALS(LogComponent::kDefault, LogComponent(componentD).parent());
        ASSERT_EQUALS(componentD, LogComponent(componentE).parent());
        ASSERT_NOT_EQUALS(LogComponent::kDefault, LogComponent(componentE).parent());

        // Log components should inherit parent's log severity in settings.
        LogComponentSettings settings;
        settings.setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Debug(1));
        settings.setMinimumLoggedSeverity(componentD, LogSeverity::Debug(2));

        // componentE should inherit componentD's log severity.
        ASSERT_TRUE(settings.shouldLog(componentE, LogSeverity::Debug(2)));
        ASSERT_FALSE(settings.shouldLog(componentE, LogSeverity::Debug(3)));

        // Clearing parent's log severity - componentE should inherit from Default.
        settings.clearMinimumLoggedSeverity(componentD);
        ASSERT_TRUE(settings.shouldLog(componentE, LogSeverity::Debug(1)));
        ASSERT_FALSE(settings.shouldLog(componentE, LogSeverity::Debug(2)));
    }
Exemple #3
0
    TEST_F(LogTestUnadornedEncoder, LogComponentSettingsMinimumLogSeverity) {
        LogComponentSettings settings;
        ASSERT_TRUE(settings.hasMinimumLogSeverity(LogComponent::kDefault));
        ASSERT_TRUE(settings.getMinimumLogSeverity(LogComponent::kDefault) == LogSeverity::Log());
        for (int i = 0; i < int(LogComponent::kNumLogComponents); ++i) {
            LogComponent component = static_cast<LogComponent::Value>(i);
            if (component == LogComponent::kDefault) { continue; }
            ASSERT_FALSE(settings.hasMinimumLogSeverity(component));
        }

        // Override and clear minimum severity level.
        for (int i = 0; i < int(LogComponent::kNumLogComponents); ++i) {
            LogComponent component = static_cast<LogComponent::Value>(i);
            LogSeverity severity = LogSeverity::Debug(2);

            // Override severity level.
            settings.setMinimumLoggedSeverity(component, severity);
            ASSERT_TRUE(settings.hasMinimumLogSeverity(component));
            ASSERT_TRUE(settings.getMinimumLogSeverity(component) == severity);

            // Clear severity level.
            // Special case: when clearing LogComponent::kDefault, the corresponding
            //               severity level is set to default values (ie. Log()).
            settings.clearMinimumLoggedSeverity(component);
            if (component == LogComponent::kDefault) {
                ASSERT_TRUE(settings.hasMinimumLogSeverity(component));
                ASSERT_TRUE(settings.getMinimumLogSeverity(LogComponent::kDefault) ==
                            LogSeverity::Log());
            }
            else {
                ASSERT_FALSE(settings.hasMinimumLogSeverity(component));
            }
        }
    }