예제 #1
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)));
    }
예제 #2
0
    // Test for shouldLog() when we have configured multiple components.
    // Minimum severity levels:
    // LogComponent::kDefault: 1
    // componentA: 2
    // componentB: 0
    TEST_F(LogTestUnadornedEncoder, LogComponentSettingsShouldLogMultipleComponentsConfigured) {
        LogComponentSettings settings;

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

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

        // Components for log message: componentB only.
        ASSERT_TRUE(settings.shouldLog(componentB, LogSeverity::Log()));
        ASSERT_FALSE(settings.shouldLog(componentB, LogSeverity::Debug(1)));

        // Components for log message: componentC only.
        // Since a component-specific minimum severity is not configured for componentC,
        // shouldLog() falls back on LogComponent::kDefault.
        ASSERT_TRUE(settings.shouldLog(componentC, LogSeverity::Debug(1)));
        ASSERT_FALSE(settings.shouldLog(componentC, 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());

    }
예제 #3
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());
    }
예제 #4
0
    // Test for shouldLog() when the minimum logged severity is set only for LogComponent::kDefault.
    TEST_F(LogTestUnadornedEncoder, LogComponentSettingsShouldLogDefaultLogComponentOnly) {
        LogComponentSettings settings;

        // Initial log severity for LogComponent::kDefault is Log().
        ASSERT_TRUE(shouldLog(LogSeverity::Info()));
        ASSERT_TRUE(shouldLog(LogSeverity::Log()));
        ASSERT_FALSE(shouldLog(LogSeverity::Debug(1)));
        ASSERT_FALSE(shouldLog(LogSeverity::Debug(2)));

        // If any components are provided to shouldLog(), we should get the same outcome
        // because we have not configured any non-LogComponent::kDefault components.
        ASSERT_TRUE(settings.shouldLog(componentA, LogSeverity::Log()));
        ASSERT_FALSE(settings.shouldLog(componentA, LogSeverity::Debug(1)));

        // Set minimum logged severity so that Debug(1) messages are written to log domain.
        settings.setMinimumLoggedSeverity(LogComponent::kDefault, LogSeverity::Debug(1));
        logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault,
                                                            LogSeverity::Debug(1));

        ASSERT_TRUE(shouldLog(LogSeverity::Info()));
        ASSERT_TRUE(shouldLog(LogSeverity::Log()));
        ASSERT_TRUE(shouldLog(LogSeverity::Debug(1)));
        ASSERT_FALSE(shouldLog(LogSeverity::Debug(2)));

        // Revert back.
        logger::globalLogDomain()->setMinimumLoggedSeverity(LogComponent::kDefault,
                                                            LogSeverity::Log());

        // Same results when components are supplied to shouldLog().
        ASSERT_TRUE(settings.shouldLog(componentA, LogSeverity::Debug(1)));
        ASSERT_FALSE(settings.shouldLog(componentA, LogSeverity::Debug(2)));
    }
예제 #5
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));
            }
        }
    }