001/* JUnit test that exports the demos. 002 003 Copyright (c) 2018 The Regents of the University of California. 004 All rights reserved. 005 Permission is hereby granted, without written agreement and without 006 license or royalty fees, to use, copy, modify, and distribute this 007 software and its documentation for any purpose, provided that the above 008 copyright notice and the following two paragraphs appear in all copies 009 of this software. 010 011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY 012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES 013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF 014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF 015 SUCH DAMAGE. 016 017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, 018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE 020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 022 ENHANCEMENTS, OR MODIFICATIONS. 023 024 PT_COPYRIGHT_VERSION_2 025 COPYRIGHTENDKEY 026 027 */ 028 029package ptolemy.vergil.basic.export.test.junit; 030 031import java.io.IOException; 032 033import org.junit.Test; 034import org.junit.runner.RunWith; 035 036import junitparams.JUnitParamsRunner; 037import junitparams.Parameters; 038 039/////////////////////////////////////////////////////////////////// 040//// ExportModelJUnitTestBatch 041/** 042 * JUnit test that exports the demos between two indices. 043 * 044 * Derived classes should override the demos() method and invoke 045 * super.demos(N,M);, where N and M are the start and end indices 046 * of the models to be exported. 047 * 048 * <p>To run the first batch of models using the baseclass: 049 * <pre> 050 * cd $PTII 051 * ./configure 052 * ant test.single -Dtest.name=ptolemy.vergil.basic.export.test.junit.ExportModelJUnitTestBatch -Djunit.formatter=plain 053 * </pre> 054 * or 055 * <pre> 056 * cd $PTII/ptolemy/vergil/basic/export/test/junit/; 057 * export CLASSPATH=${PTII}:${PTII}/lib/junit-4.8.2.jar:${PTII}/lib/JUnitParams-0.3.0.jar${PTII}:${PTII}/lib/junit-4.8.2.jar:${PTII}/lib/JUnitParams-0.3.0.jar; 058 * export JAVAFLAGS="-Dptolemy.ptII.exportHTML.linkToJNLP=true -Dptolemy.ptII.exportHTML.usePtWebsite=true" 059 * $PTII/bin/ptinvoke org.junit.runner.JUnitCore ptolemy.vergil.basic.export.test.junit.ExportModelJUnitTestBatch 060 * </pre> 061 * <p> 062 * This test uses JUnitParams from <a 063 * href="http://code.google.com/p/junitparams/#in_browser"http://code.google.com/p/junitparams/</a>, 064 * which is released under <a href="http://www.apache.org/licenses/LICENSE-2.0#in_browser">Apache License 2.0</a>. 065 * </p> 066 * 067 * @author Christopher Brooks 068 * @version $Id$ 069 * @since Ptolemy II 11.0 070 * @Pt.ProposedRating Green (cxh) 071 * @Pt.AcceptedRating Red (cxh) 072 */ 073@RunWith(JUnitParamsRunner.class) 074public class ExportModelJUnitTestBatch extends ExportModelJUnitTest { 075 /** Export a model. 076 * @param modelPath The model to be exported. The code is exported to 077 * the directory contained by the model. 078 * @exception Throwable If there is a problem reading or exporting the model. 079 */ 080 @Override 081 @Test 082 @Parameters(method = "demos") 083 public void RunExportModel(String modelPath) throws Throwable { 084 super.RunExportModel(modelPath); 085 } 086 087 /** 088 * Return a two dimensional array of arrays of strings that name the 089 * first 51 models to be exported. 090 * 091 * Derived classes should override this method with the 092 * range of demos to be exported. 093 * 094 * @return a two dimension array of arrays of strings that name the 095 * models to be exported. 096 * @exception IOException If there is a problem accessing the directory. 097 */ 098 @Override 099 public Object[] demos() throws IOException { 100 return demos(0, 50); 101 } 102 103 /** Return a two dimensional array of strings that name the models to 104 * to be exported. 105 * @param start The 0-based index of the first model in 106 * $PTII/ptolemy/configs/doc/models.txt 107 * @param end The index of the last model. 108 * @return a two dimension array of arrays of strings that name the 109 * models to be exported. 110 * @exception IOException If there is a problem accessing the directory. 111 */ 112 public Object[] demos(int start, int end) throws IOException { 113 if (start < 0 || end < 0) { 114 throw new IllegalArgumentException("The start indice (" + start 115 + ") or the end indice (" + end + ") is less than zero."); 116 } 117 if (start >= end) { 118 throw new IllegalArgumentException("The start indice (" + start 119 + ") must be greater than the end indice (" + end + ")"); 120 } 121 Object[] allDemos = super.demos(); 122 System.out.println("ExportModeJUnitTestBatch: There are " 123 + allDemos.length + " demos. Exporting demos: " + start + " to " 124 + end + "."); 125 126 if (allDemos.length < start) { 127 System.out.println( 128 "ExportModeJUnitTestBatch: There are " + allDemos.length 129 + " demos, which is less than the start index " 130 + start + ". Returning an empty array of demos."); 131 return new Object[0][1]; 132 } 133 if (allDemos.length < end) { 134 end = allDemos.length - 1; 135 System.out.println( 136 "ExportModeJUnitTestBatch: There are " + allDemos.length 137 + " demos, which is less than the end index " 138 + start + ". Setting the end index to " + end); 139 } 140 Object[][] subDemos = new Object[end - start + 1][1]; 141 System.arraycopy(allDemos, start, subDemos, 0, end - start + 1); 142 return subDemos; 143 } 144}