2 * Copyright (c) 2015 Huawei, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 /* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 5.0 */
9 /* JavaCCOptions:STATIC=true,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
10 package org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOParse;
12 import junit.framework.TestCase;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.nemo.user.vnspacemanager.languagestyle.NEMOParse.SimpleCharStream;
18 import java.io.IOException;
19 import java.io.InputStream;
20 import java.io.Reader;
21 import java.lang.reflect.Field;
23 import static org.junit.Assert.*;
24 import static org.mockito.Mockito.*;
26 * Created by zhangmeng on 2015/12/16.
28 public class SimpleCharStreamTest extends TestCase {
29 private SimpleCharStream simpleCharStream;
30 private Reader reader;
31 private InputStream inputStream;
32 private Reader reader_empty;
33 private Class<SimpleCharStream> class1 ;
37 public void setUp() throws Exception {
38 class1 = SimpleCharStream.class;
39 field = class1.getDeclaredField("inputStream");
40 field.setAccessible(true);
41 field.set(class1,null);
42 reader = new Reader() {
44 public int read(char[] cbuf, int off, int len) throws IOException {
49 public void close() throws IOException {
53 inputStream = new InputStream() {
55 public int read() throws IOException {
64 public void testInit()throws Exception{
65 InputStream inputStream_empty = null;
67 simpleCharStream = new SimpleCharStream(reader,1,1,1);
68 Assert.assertTrue(simpleCharStream != null);
69 simpleCharStream.ReInit(reader_empty, 1, 1, 1);
71 simpleCharStream = new SimpleCharStream(reader,1,1);
72 Assert.assertTrue(simpleCharStream != null);
73 simpleCharStream.ReInit(reader_empty, 1, 1);
75 simpleCharStream = new SimpleCharStream(reader);
76 Assert.assertTrue(simpleCharStream != null);
77 simpleCharStream.ReInit(reader_empty);
79 simpleCharStream = new SimpleCharStream(inputStream,null,1,1,1);
80 Assert.assertTrue(simpleCharStream != null);
81 simpleCharStream.ReInit(inputStream, null, 1, 1, 1);
82 simpleCharStream.ReInit(reader_empty);
84 simpleCharStream = new SimpleCharStream(inputStream,null,1,1);
85 Assert.assertTrue(simpleCharStream != null);
86 simpleCharStream.ReInit(inputStream, null, 1, 1);
87 simpleCharStream.ReInit(reader_empty);
89 simpleCharStream = new SimpleCharStream(inputStream,1,1);
90 Assert.assertTrue(simpleCharStream != null);
91 simpleCharStream.ReInit(inputStream, 1, 1);
92 simpleCharStream.ReInit(reader_empty);
94 simpleCharStream = new SimpleCharStream(inputStream,null);
95 Assert.assertTrue(simpleCharStream != null);
96 simpleCharStream.ReInit(inputStream, null);
97 simpleCharStream.ReInit(reader_empty);
99 simpleCharStream = new SimpleCharStream(inputStream);
100 Assert.assertTrue(simpleCharStream != null);
101 simpleCharStream.ReInit(inputStream);
102 simpleCharStream.ReInit(reader_empty);
107 public void testSetTabSize() throws Exception {
112 public void testGetTabSize() throws Exception {
117 public void testBeginToken_ReadChar_FillBuff_ExpandBuff() throws Exception {
118 Assert.assertTrue(simpleCharStream == null);
119 simpleCharStream = new SimpleCharStream(reader,1,1,1);
120 SimpleCharStream.BeginToken();
121 Assert.assertTrue(simpleCharStream != null);
123 // Assert.assertTrue(SimpleCharStream.getColumn() == 0);
124 // Assert.assertTrue(SimpleCharStream.getLine() == 0);
125 Assert.assertTrue(SimpleCharStream.getEndColumn() != 0);
126 Assert.assertTrue(SimpleCharStream.getEndLine() != 0);
127 Assert.assertTrue(SimpleCharStream.getBeginColumn() != 0);
128 Assert.assertTrue(SimpleCharStream.getBeginLine() != 0);
130 SimpleCharStream.backup(1);
131 Assert.assertTrue(SimpleCharStream.GetImage() != null);
132 Assert.assertTrue(SimpleCharStream.GetSuffix(1).length != 0);
133 SimpleCharStream.adjustBeginLineColumn(1, 1);
134 SimpleCharStream.Done();
135 simpleCharStream.ReInit(reader_empty);