Home | History | Annotate | Download | only in format
      1 /*
      2  * Copyright (C) 2011 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.ide.eclipse.gltrace.format;
     18 
     19 import static org.junit.Assert.*;
     20 
     21 import com.android.ide.eclipse.gltrace.GLProtoBuf.GLMessage.DataType.Type;
     22 
     23 import org.junit.Test;
     24 
     25 import java.util.Arrays;
     26 import java.util.List;
     27 
     28 public class GLAPISpecTest {
     29     @Test
     30     public void testParser() {
     31         String returnType = "void";
     32         String funcName = "glDiscardFramebufferEXT";
     33         List<String> args = Arrays.asList(
     34                 "GLenum target",
     35                 "GLsizei numAttachments",
     36                 "const GLenum* attachments");
     37 
     38         GLAPISpec spec = GLAPISpec.parseLine(createSpec(returnType, funcName, args));
     39 
     40         assertEquals(Type.VOID, spec.getReturnValue().getDataType());
     41         assertEquals(returnType, spec.getReturnValue().getCType());
     42         assertEquals(funcName, spec.getFunction());
     43 
     44         List<GLDataTypeSpec> argSpecs = spec.getArgs();
     45         assertEquals(argSpecs.size(), args.size());
     46 
     47         GLDataTypeSpec argSpec = argSpecs.get(0);
     48         assertEquals(argSpec.getArgName(), "target");
     49         assertEquals(argSpec.getDataType(), Type.ENUM);
     50         assertEquals(argSpec.isPointer(), false);
     51 
     52         argSpec = argSpecs.get(2);
     53         assertEquals(argSpec.getArgName(), "attachments");
     54         assertEquals(argSpec.getDataType(), Type.ENUM);
     55         assertEquals(argSpec.isPointer(), true);
     56     }
     57 
     58     private String createSpec(String returnType, String funcName, List<String> args) {
     59         StringBuffer sb = new StringBuffer();
     60         sb.append(String.format("%s, %s", returnType, funcName));
     61 
     62         if (args != null) {
     63             sb.append(", ");
     64             for (int i = 0; i < args.size(); i++) {
     65                 sb.append(args.get(i));
     66                 if (i != args.size() - 1) {
     67                     sb.append(", ");
     68                 }
     69             }
     70         }
     71 
     72         return sb.toString();
     73     }
     74 }
     75