mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-13 02:32:09 +10:00
datasheet fix
This commit is contained in:
@@ -25,7 +25,7 @@ Elna Silmic II,16 V,330 uF,20,12.5,5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,16 V,470 uF,25,12.5,5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,16 V,1000 uF,31.5,16,7.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,16 V,2200 uF,40,18,7.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,25 V,4.7uF,11,5,2,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,25 V,4.7 uF,11,5,2,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,25 V,10 uF,11,6.3,2.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,25 V,22 uF,11,6.3,2.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,25 V,33 uF,11.5,8,3.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
@@ -35,7 +35,7 @@ Elna Silmic II,25 V,220 uF,20,12.5,5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,25 V,330 uF,25,12.5,5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,25 V,470 uF,25,16,7.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,25 V,1000 uF,35.5,16,7.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,35 V,4.7uF,11,5,2,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,35 V,4.7 uF,11,5,2,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,35 V,10 uF,11,6.3,2.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,35 V,22 uF,11.5,8,3.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,35 V,33 uF,12.5,10,5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
@@ -47,7 +47,7 @@ Elna Silmic II,35 V,470 uF,31.5,16,7.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,35 V,1000 uF,35.5,18,7.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,50 V,2.2 uF,11,6.3,2.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,50 V,3.3 uF,11,6.3,2.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,50 V,4.7uF,11,6.3,2.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,50 V,4.7 uF,11,6.3,2.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,50 V,10 uF,11.5,8,3.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,50 V,22 uF,12.5,10,5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,50 V,33 uF,16,10,5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
@@ -59,7 +59,7 @@ Elna Silmic II,50 V,470 uF,35.5,16,7.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,50 V,1000 uF,40,18,7.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,63 V,2.2 uF,11,5,2,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,63 V,3.3 uF,11,5,2,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,63 V,4.7uF,11,6.3,2.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,63 V,4.7 uF,11,6.3,2.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,63 V,10 uF,11.5,8,3.5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,63 V,22 uF,16,10,5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
Elna Silmic II,63 V,33 uF,20,10,5,#876B68,#544341,#FFFFFF,#CCCCCC,#544341
|
||||
|
||||
@@ -1404,8 +1404,8 @@ WIMA MKS-4,250 V,82 uF B,57,35,52.5,#FF6666,#A03140,#000000,BOX
|
||||
WIMA MKS-4,250 V,100 uF A,57,45,52.5,#FF6666,#A03140,#000000,BOX
|
||||
WIMA MKS-4,250 V,120 uF B,57,45,52.5,#FF6666,#A03140,#000000,BOX
|
||||
WIMA MKS-4,250 V,150 uF,57,45,52.5,#FF6666,#A03140,#000000,BOX
|
||||
WIMA MKS-4,400 V,0.01µF A,10,3,7.5,#FF6666,#A03140,#000000,BOX
|
||||
WIMA MKS-4,400 V,0.01µF B,13,4,10,#FF6666,#A03140,#000000,BOX
|
||||
WIMA MKS-4,400 V,0.01 uF A,10,3,7.5,#FF6666,#A03140,#000000,BOX
|
||||
WIMA MKS-4,400 V,0.01 uF B,13,4,10,#FF6666,#A03140,#000000,BOX
|
||||
WIMA MKS-4,400 V,0.015 uF A,10,3,7.5,#FF6666,#A03140,#000000,BOX
|
||||
WIMA MKS-4,400 V,0.015 uF B,13,4,10,#FF6666,#A03140,#000000,BOX
|
||||
WIMA MKS-4,400 V,0.022 uF A,10,4,7.5,#FF6666,#A03140,#000000,BOX
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
|
||||
DIY Layout Creator (DIYLC).
|
||||
Copyright (c) 2009-2025 held jointly by the individual authors.
|
||||
|
||||
This file is part of DIYLC.
|
||||
|
||||
DIYLC is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
DIYLC is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
*/
|
||||
package org.diylc.components;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.diylc.TestConfiguration;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDatasheetSupport;
|
||||
import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.presenter.DatasheetService;
|
||||
import org.diylc.utils.ReflectionUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Applies every row of every datasheet to its component, so a malformed row fails the build rather
|
||||
* than the user's Apply Model, or an AI edit that picks the model. The components are found through
|
||||
* the class index, so a new datasheet is covered without touching this test.
|
||||
*/
|
||||
public class DatasheetRowsTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUp() {
|
||||
TestConfiguration.initialize();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void everyRowApplies() throws ReflectiveOperationException {
|
||||
List<String> failures = new ArrayList<String>();
|
||||
for (Class<? extends IDIYComponent<?>> type : datasheetComponents()) {
|
||||
List<String[]> datasheet = DatasheetService.getInstance().loadDatasheet(type);
|
||||
Assert.assertNotNull(type.getSimpleName(), datasheet);
|
||||
Assert.assertFalse(type.getSimpleName(), datasheet.isEmpty());
|
||||
for (String[] row : datasheet) {
|
||||
IDatasheetSupport component =
|
||||
(IDatasheetSupport) type.getDeclaredConstructor().newInstance();
|
||||
try {
|
||||
component.applyModel(row);
|
||||
} catch (RuntimeException e) {
|
||||
failures.add(type.getSimpleName() + ": " + String.join(",", row) + " -> " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
Assert.assertTrue(String.join("\n", failures), failures.isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* DatasheetService decodes with the platform charset, where a latin-1 byte such as the micro
|
||||
* sign turns into U+FFFD instead of failing, so units are written as uF.
|
||||
*/
|
||||
@Test
|
||||
public void datasheetsAreAscii() throws IOException {
|
||||
List<String> failures = new ArrayList<String>();
|
||||
for (Class<? extends IDIYComponent<?>> type : datasheetComponents()) {
|
||||
String fileName = type.getSimpleName() + ".datasheet";
|
||||
try (InputStream in = type.getResourceAsStream("/datasheets/" + fileName)) {
|
||||
Assert.assertNotNull(fileName, in);
|
||||
int line = 1;
|
||||
int b;
|
||||
while ((b = in.read()) != -1) {
|
||||
if (b == '\n') {
|
||||
line++;
|
||||
} else if (b > 0x7f) {
|
||||
failures.add(fileName + ":" + line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Assert.assertTrue("non-ASCII bytes at " + failures, failures.isEmpty());
|
||||
}
|
||||
|
||||
/** A datasheet is found by the class name, so a file no component claims is never loaded. */
|
||||
@Test
|
||||
public void everyDatasheetFileHasAComponent() throws URISyntaxException {
|
||||
URL folder = DatasheetRowsTest.class.getResource("/datasheets");
|
||||
Assert.assertNotNull(folder);
|
||||
Set<String> claimed = new HashSet<String>();
|
||||
for (Class<? extends IDIYComponent<?>> type : datasheetComponents()) {
|
||||
claimed.add(type.getSimpleName() + ".datasheet");
|
||||
}
|
||||
for (String fileName : new File(folder.toURI()).list()) {
|
||||
Assert.assertTrue(fileName + " belongs to no datasheet component",
|
||||
claimed.contains(fileName));
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static List<Class<? extends IDIYComponent<?>>> datasheetComponents() {
|
||||
List<Class<? extends IDIYComponent<?>>> types =
|
||||
new ArrayList<Class<? extends IDIYComponent<?>>>();
|
||||
for (Class<?> type : ReflectionUtils.getIndexedClasses(IDIYComponent.class)) {
|
||||
ComponentDescriptor descriptor = type.getAnnotation(ComponentDescriptor.class);
|
||||
if (descriptor != null && descriptor.enableDatasheet()
|
||||
&& !Modifier.isAbstract(type.getModifiers())) {
|
||||
Assert.assertTrue(type.getSimpleName() + " enables a datasheet without IDatasheetSupport",
|
||||
IDatasheetSupport.class.isAssignableFrom(type));
|
||||
types.add((Class<? extends IDIYComponent<?>>) type);
|
||||
}
|
||||
}
|
||||
Assert.assertFalse("no datasheet components in the class index", types.isEmpty());
|
||||
return types;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user