Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Android/art/art/test/688-shared-library/src-art/   (Android Betriebssystem Version 17©)  Datei vom 26.5.2026 mit Größe 8 kB image not shown  

Quelle  Main.java

  Sprache: JAVA
 

/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


import dalvik.system.DelegateLastClassLoader;
import dalvik.system.PathClassLoader;

public class Main {
    static final String TEST_NAME = "688-shared-library";
    static final String MAIN_JAR_FILE = System.getenv("DEX_LOCATION") + "/" + TEST_NAME + ".jar";
    static final String EX_JAR_FILE = System.getenv("DEX_LOCATION") + "/" + TEST_NAME + "-ex.jar";
    static ClassLoader bootLoader = Object.class.getClassLoader();

    public static void main(String[] args) throws Exception {
      testNoLibrary();
      testOneLibrary();
      testTwoLibraries1();
      testTwoLibraries2();
      testTransitive1();
      testTransitive2();
      testTransitive3();
      testTransitive4();
    }

    public static void assertIdentical(Object expected, Object actual) {
      if (expected != actual) {
        throw new Error("Expected " + expected + ", got " + actual);
      }
    }

    public static void testNoLibrary() throws Exception {
      ClassLoader loader = new PathClassLoader(MAIN_JAR_FILE, null, bootLoader);
      Class<?> cls = loader.loadClass("Main");
      assertIdentical(loader, cls.getClassLoader());
    }

    public static void testOneLibrary() throws Exception {
      ClassLoader[] sharedLibraries = {
          new PathClassLoader(EX_JAR_FILE, null, bootLoader),
      };
      ClassLoader delegateFirst =
          new PathClassLoader(MAIN_JAR_FILE, null, bootLoader, sharedLibraries);
      Class<?> cls = delegateFirst.loadClass("Main");
      assertIdentical(sharedLibraries[0], cls.getClassLoader());
      cls = delegateFirst.loadClass("SharedLibraryOne");
      assertIdentical(sharedLibraries[0], cls.getClassLoader());
      
      ClassLoader delegateLast =
          new DelegateLastClassLoader(MAIN_JAR_FILE, null, bootLoader, sharedLibraries);
      cls = delegateLast.loadClass("Main");
      assertIdentical(sharedLibraries[0], cls.getClassLoader());
      cls = delegateLast.loadClass("SharedLibraryOne");
      assertIdentical(sharedLibraries[0], cls.getClassLoader());
    }
    
    public static void testTwoLibraries1() throws Exception {
      ClassLoader[] sharedLibraries = {
          new PathClassLoader(MAIN_JAR_FILE, null, bootLoader),
          new PathClassLoader(EX_JAR_FILE, null, bootLoader),
      };
      ClassLoader delegateFirst = new PathClassLoader(""null, bootLoader, sharedLibraries);
      Class<?> cls = delegateFirst.loadClass("Main");
      assertIdentical(sharedLibraries[0], cls.getClassLoader());
      cls = delegateFirst.loadClass("SharedLibraryOne");
      assertIdentical(sharedLibraries[1], cls.getClassLoader());
      
      ClassLoader delegateLast =
          new DelegateLastClassLoader(MAIN_JAR_FILE, null, bootLoader, sharedLibraries);
      cls = delegateLast.loadClass("Main");
      assertIdentical(sharedLibraries[0], cls.getClassLoader());
      cls = delegateLast.loadClass("SharedLibraryOne");
      assertIdentical(sharedLibraries[1], cls.getClassLoader());
    }
    
    public static void testTwoLibraries2() throws Exception {
      ClassLoader[] sharedLibraries = {
          new PathClassLoader(EX_JAR_FILE, null, bootLoader),
          new PathClassLoader(MAIN_JAR_FILE, null, bootLoader),
      };
      ClassLoader delegateFirst = new PathClassLoader(""null, bootLoader, sharedLibraries);
      Class<?> cls = delegateFirst.loadClass("Main");
      assertIdentical(sharedLibraries[0], cls.getClassLoader());
      cls = delegateFirst.loadClass("SharedLibraryOne");
      assertIdentical(sharedLibraries[0], cls.getClassLoader());
      
      ClassLoader delegateLast = new DelegateLastClassLoader(""null, bootLoader, sharedLibraries);
      cls = delegateLast.loadClass("Main");
      assertIdentical(sharedLibraries[0], cls.getClassLoader());
      cls = delegateLast.loadClass("SharedLibraryOne");
      assertIdentical(sharedLibraries[0], cls.getClassLoader());
    }

    public static void testTransitive1() throws Exception {
      ClassLoader[] sharedLibraryLevel2 = {
          new PathClassLoader(EX_JAR_FILE, null, bootLoader),
      };
      ClassLoader[] sharedLibraryLevel1 = {
          new PathClassLoader(MAIN_JAR_FILE, null, bootLoader, sharedLibraryLevel2),
      };

      ClassLoader delegateFirst = new PathClassLoader(""null, bootLoader, sharedLibraryLevel1);
      Class<?> cls = delegateFirst.loadClass("Main");
      assertIdentical(sharedLibraryLevel2[0], cls.getClassLoader());
      cls = delegateFirst.loadClass("SharedLibraryOne");
      assertIdentical(sharedLibraryLevel2[0], cls.getClassLoader());
      
      ClassLoader delegateLast =
          new DelegateLastClassLoader(""null, bootLoader, sharedLibraryLevel1);
      cls = delegateLast.loadClass("Main");
      assertIdentical(sharedLibraryLevel2[0], cls.getClassLoader());
      cls = delegateLast.loadClass("SharedLibraryOne");
      assertIdentical(sharedLibraryLevel2[0], cls.getClassLoader());
    }
    
    public static void testTransitive2() throws Exception {
      ClassLoader[] sharedLibraryLevel2 = {
          new PathClassLoader(MAIN_JAR_FILE, null, bootLoader),
      };
      ClassLoader[] sharedLibraryLevel1 = {
          new PathClassLoader(EX_JAR_FILE, null, bootLoader, sharedLibraryLevel2),
      };

      ClassLoader delegateFirst = new PathClassLoader(""null, bootLoader, sharedLibraryLevel1);
      Class<?> cls = delegateFirst.loadClass("Main");
      assertIdentical(sharedLibraryLevel2[0], cls.getClassLoader());
      cls = delegateFirst.loadClass("SharedLibraryOne");
      assertIdentical(sharedLibraryLevel1[0], cls.getClassLoader());
      
      ClassLoader delegateLast =
          new DelegateLastClassLoader(""null, bootLoader, sharedLibraryLevel1);
      cls = delegateLast.loadClass("Main");
      assertIdentical(sharedLibraryLevel2[0], cls.getClassLoader());
      cls = delegateLast.loadClass("SharedLibraryOne");
      assertIdentical(sharedLibraryLevel1[0], cls.getClassLoader());
    }

    public static void testTransitive3() throws Exception {
      ClassLoader[] sharedLibraryLevel2 = {
          new PathClassLoader(MAIN_JAR_FILE, null, bootLoader),
      };
      ClassLoader[] sharedLibraryLevel1 = {
          new PathClassLoader(EX_JAR_FILE, null, bootLoader, sharedLibraryLevel2),
          sharedLibraryLevel2[0],
      };

      ClassLoader delegateFirst = new PathClassLoader(""null, bootLoader, sharedLibraryLevel1);
      Class<?> cls = delegateFirst.loadClass("Main");
      assertIdentical(sharedLibraryLevel2[0], cls.getClassLoader());
      cls = delegateFirst.loadClass("SharedLibraryOne");
      assertIdentical(sharedLibraryLevel1[0], cls.getClassLoader());
      
      ClassLoader delegateLast =
          new DelegateLastClassLoader(""null, bootLoader, sharedLibraryLevel1);
      cls = delegateLast.loadClass("Main");
      assertIdentical(sharedLibraryLevel2[0], cls.getClassLoader());
      cls = delegateLast.loadClass("SharedLibraryOne");
      assertIdentical(sharedLibraryLevel1[0], cls.getClassLoader());
    }
    
    public static void testTransitive4() throws Exception {
      ClassLoader[] sharedLibraryLevel2 = {
          new PathClassLoader(EX_JAR_FILE, null, bootLoader),
      };
      ClassLoader[] sharedLibraryLevel1 = {
          new PathClassLoader(MAIN_JAR_FILE, null, bootLoader, sharedLibraryLevel2),
          sharedLibraryLevel2[0],
      };

      ClassLoader delegateFirst = new PathClassLoader(""null, bootLoader, sharedLibraryLevel1);
      Class<?> cls = delegateFirst.loadClass("Main");
      assertIdentical(sharedLibraryLevel2[0], cls.getClassLoader());
      cls = delegateFirst.loadClass("SharedLibraryOne");
      assertIdentical(sharedLibraryLevel2[0], cls.getClassLoader());
      
      ClassLoader delegateLast =
          new DelegateLastClassLoader(""null, bootLoader, sharedLibraryLevel1);
      cls = delegateLast.loadClass("Main");
      assertIdentical(sharedLibraryLevel2[0], cls.getClassLoader());
      cls = delegateLast.loadClass("SharedLibraryOne");
      assertIdentical(sharedLibraryLevel2[0], cls.getClassLoader());
    }
}

Messung V0.5 in Prozent
C=80 H=89 G=84

¤ Dauer der Verarbeitung: 0.1 Sekunden  (vorverarbeitet am  2026-06-29) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.