hotspot/test/native/logging/test_logTagSetDescriptions.cpp
author mlarsson
Thu, 08 Sep 2016 15:24:52 +0200
changeset 41676 45778d817919
child 43431 5ffa076f526d
permissions -rw-r--r--
8165698: Convert LogTagSet related internal tests to GTest Reviewed-by: rehn, rprotacio
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41676
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
     1
/*
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
     4
 *
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
     7
 * published by the Free Software Foundation.
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
     8
 *
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    13
 * ac_heapanied this code).
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    14
 *
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    18
 *
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    21
 * questions.
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    22
 *
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    23
 */
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    24
#include "precompiled.hpp"
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    25
#include "logTestUtils.inline.hpp"
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    26
#include "logging/logConfiguration.hpp"
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    27
#include "logging/logTagSet.hpp"
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    28
#include "logging/logTagSetDescriptions.hpp"
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    29
#include "memory/resourceArea.hpp"
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    30
#include "unittest.hpp"
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    31
#include "utilities/ostream.hpp"
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    32
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    33
TEST(LogTagSetDescriptions, describe) {
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    34
  for (LogTagSetDescription* d = tagset_descriptions; d->tagset != NULL; d++) {
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    35
    char expected[1 * K];
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    36
    d->tagset->label(expected, sizeof(expected), "+");
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    37
    jio_snprintf(expected + strlen(expected),
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    38
                 sizeof(expected) - strlen(expected),
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    39
                 ": %s", d->descr);
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    40
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    41
    ResourceMark rm;
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    42
    stringStream stream;
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    43
    LogConfiguration::describe(&stream);
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    44
    EXPECT_PRED2(string_contains_substring, stream.as_string(), expected)
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    45
      << "missing log tag set descriptions in LogConfiguration::describe";
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    46
  }
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    47
}
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    48
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    49
TEST(LogTagSetDescriptions, command_line_help) {
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    50
  const char* filename = "logtagset_descriptions";
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    51
  FILE* fp = fopen(filename, "w+");
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    52
  ASSERT_NE((void*)NULL, fp);
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    53
  LogConfiguration::print_command_line_help(fp);
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    54
  fclose(fp);
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    55
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    56
  for (LogTagSetDescription* d = tagset_descriptions; d->tagset != NULL; d++) {
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    57
    char expected[1 * K];
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    58
    d->tagset->label(expected, sizeof(expected), "+");
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    59
    jio_snprintf(expected + strlen(expected),
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    60
                 sizeof(expected) - strlen(expected),
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    61
                 ": %s", d->descr);
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    62
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    63
    EXPECT_TRUE(file_contains_substring(filename, expected)) << "missing log tag set descriptions in -Xlog:help output";
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    64
  }
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    65
  delete_file(filename);
45778d817919 8165698: Convert LogTagSet related internal tests to GTest
mlarsson
parents:
diff changeset
    66
}