hotspot/test/native/runtime/test_arguments.cpp
author hseigel
Wed, 01 Mar 2017 08:00:02 -0500
changeset 46194 5596e6f63072
parent 41705 332239c052cc
child 46560 388aa8d67c80
permissions -rw-r--r--
8172307: Remove ununsed JVM API JVM_GetModuleByPackageName() Summary: Remove get_module_by_package_name() etc., and unneeded test. Reviewed-by: sspitsyn, gtriantafill
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39621
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
     1
/*
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
     4
 *
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
     7
 * published by the Free Software Foundation.
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
     8
 *
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    13
 * accompanied this code).
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    14
 *
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    18
 *
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    21
 * questions.
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    22
 */
41705
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 39621
diff changeset
    23
39621
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    24
#include "precompiled.hpp"
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    25
#include "runtime/arguments.hpp"
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    26
#include "unittest.hpp"
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    27
#include "utilities/globalDefinitions.hpp"
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    28
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    29
TEST(arguments, atojulong) {
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    30
  char ullong_max[32];
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    31
  int ret = jio_snprintf(ullong_max, sizeof(ullong_max), JULONG_FORMAT, ULLONG_MAX);
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    32
  ASSERT_NE(-1, ret);
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    33
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    34
  julong value;
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    35
  const char* invalid_strings[] = {
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    36
    "", "-1", "-100", " 1", "2 ", "3 2", "1.0",
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    37
    "0x4.5", "0x", "0x0x1" "0.001", "4e10", "e"
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    38
    "K", "M", "G", "1MB", "1KM", "AA", "0B",
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    39
    "18446744073709551615K", "17179869184G",
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    40
    "999999999999999999999999999999"
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    41
  };
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    42
  for (uint i = 0; i < ARRAY_SIZE(invalid_strings); i++) {
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    43
    ASSERT_FALSE(Arguments::atojulong(invalid_strings[i], &value))
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    44
        << "Invalid string '" << invalid_strings[i] << "' parsed without error.";
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    45
  }
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    46
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    47
  struct {
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    48
    const char* str;
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    49
    julong expected_value;
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    50
  } valid_strings[] = {
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    51
      { "0", 0 },
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    52
      { "4711", 4711 },
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    53
      { "1K", 1ULL * K },
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    54
      { "1k", 1ULL * K },
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    55
      { "2M", 2ULL * M },
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    56
      { "2m", 2ULL * M },
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    57
      { "4G", 4ULL * G },
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    58
      { "4g", 4ULL * G },
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    59
      { "0K", 0 },
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    60
      { ullong_max, ULLONG_MAX },
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    61
      { "0xcafebabe", 0xcafebabe },
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    62
      { "0XCAFEBABE", 0xcafebabe },
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    63
      { "0XCAFEbabe", 0xcafebabe },
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    64
      { "0x10K", 0x10 * K }
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    65
  };
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    66
  for (uint i = 0; i < ARRAY_SIZE(valid_strings); i++) {
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    67
    ASSERT_TRUE(Arguments::atojulong(valid_strings[i].str, &value))
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    68
        << "Valid string '" << valid_strings[i].str << "' did not parse.";
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    69
    ASSERT_EQ(valid_strings[i].expected_value, value);
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    70
  }
b475d96f8008 8159695: Arguments::atojulong() fails to detect overflows
mlarsson
parents:
diff changeset
    71
}