1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.protolog.tool 18 19 import org.junit.Assert.assertEquals 20 import org.junit.Test 21 22 class ProtoLogToolTest { 23 24 @Test generateLogGroupCachenull25 fun generateLogGroupCache() { 26 val groups = mapOf( 27 "GROUP1" to LogGroup("GROUP1", true, true, "TAG1"), 28 "GROUP2" to LogGroup("GROUP2", true, true, "TAG2") 29 ) 30 val code = ProtoLogTool.generateLogGroupCache("org.example", "ProtoLog\$Cache", 31 groups, "org.example.ProtoLogImpl", "org.example.ProtoLogGroups") 32 33 assertEquals(""" 34 package org.example; 35 36 public class ProtoLog${'$'}Cache { 37 public static boolean GROUP1_enabled = false; 38 public static boolean GROUP2_enabled = false; 39 40 static { 41 org.example.ProtoLogImpl.sCacheUpdater = ProtoLog${'$'}Cache::update; 42 update(); 43 } 44 45 static void update() { 46 GROUP1_enabled = org.example.ProtoLogImpl.isEnabled(org.example.ProtoLogGroups.GROUP1); 47 GROUP2_enabled = org.example.ProtoLogImpl.isEnabled(org.example.ProtoLogGroups.GROUP2); 48 } 49 } 50 """.trimIndent(), code) 51 } 52 }