1 /*
   2  * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 /*
  24  */
  25 package org.graalvm.compiler.jtt.lang;
  26 
  27 import java.util.Collections;
  28 import java.util.HashMap;
  29 import java.util.Map;
  30 
  31 import org.junit.Test;
  32 
  33 import org.graalvm.compiler.jtt.JTTTest;
  34 
  35 public final class ProcessEnvironment_init extends JTTTest {
  36 
  37     private static HashMap<Object, Object> theEnvironment;
  38     public static Map<Object, Object> theUnmodifiableEnvironment;
  39 
  40     public static int test(int v) {
  41 
  42         byte[][] environ = environ();
  43         theEnvironment = new HashMap<>(environ.length / 2 + 3);
  44 
  45         for (int i = environ.length - 1; i > 0; i -= 2) {
  46             theEnvironment.put(Variable.valueOf(environ[i - 1]), Value.valueOf(environ[i]));
  47         }
  48 
  49         theUnmodifiableEnvironment = Collections.unmodifiableMap(new StringEnvironment(theEnvironment));
  50 
  51         return v;
  52     }
  53 
  54     @SuppressWarnings("serial")
  55     private static final class StringEnvironment extends HashMap<Object, Object> {
  56 
  57         @SuppressWarnings("unused")
  58         StringEnvironment(HashMap<Object, Object> theenvironment) {
  59         }
  60     }
  61 
  62     private static final class Variable {
  63 
  64         @SuppressWarnings("unused")
  65         public static Object valueOf(byte[] bs) {
  66             return new Object();
  67         }
  68     }
  69 
  70     private static final class Value {
  71 
  72         @SuppressWarnings("unused")
  73         public static Object valueOf(byte[] bs) {
  74             return new Object();
  75         }
  76     }
  77 
  78     private static byte[][] environ() {
  79         return new byte[3][3];
  80     }
  81 
  82     @Test
  83     public void run0() throws Throwable {
  84         runTest("test", 7);
  85     }
  86 
  87 }