Skip to content

Commit a50ceea

Browse files
author
jan
committed
Add test on download and install lib on usage.
Both test that when user does not wnat to download install Sloeber does not do it and the reverse.
1 parent 6b02f9d commit a50ceea

File tree

4 files changed

+81
-21
lines changed

4 files changed

+81
-21
lines changed

io.sloeber.core/src/io/sloeber/arduinoFramework/internal/ArduinoLibraryVersion.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public ArduinoLibraryVersion(JsonElement json, ArduinoLibrary arduinoLibrary) {
6767
archiveFileName = getSafeString(jsonObject, "archiveFileName");
6868
size = jsonObject.get("size").getAsInt();
6969
checksum = getSafeString(jsonObject, "checksum");
70-
calculateFQN();
70+
myFQN=calculateFQN(getName());
7171
} catch (Exception e) {
7272
throw new JsonParseException("failed to parse json " + e.getMessage(),e);
7373
}
@@ -205,9 +205,8 @@ public IPath getExamplePath() {
205205
return getInstallPath().append(EXAMPLES_FOLDER);
206206
}
207207

208-
private void calculateFQN() {
209-
myFQN= Path.fromPortableString(SLOEBER_LIBRARY_FQN);
210-
myFQN=myFQN.append(MANAGED).append(getName());
208+
static public IPath calculateFQN(String libName) {
209+
return Path.fromPortableString(SLOEBER_LIBRARY_FQN).append(MANAGED).append(libName);
211210
}
212211

213212
@Override

io.sloeber.tests/src/io/sloeber/core/BuildTests.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.eclipse.core.resources.ResourcesPlugin;
3232
import org.eclipse.core.runtime.CoreException;
3333
import org.eclipse.core.runtime.IPath;
34+
import org.eclipse.core.runtime.IProgressMonitor;
3435
import org.eclipse.core.runtime.NullProgressMonitor;
3536
import org.junit.jupiter.api.BeforeAll;
3637
import org.junit.jupiter.api.BeforeEach;
@@ -792,4 +793,43 @@ public void NightlyBoardPatron(String name, MCUBoard boardID, Example example, C
792793

793794
}
794795

796+
@Test
797+
public void onlyInstallLibraryWhenAllowed() throws Exception {
798+
String libName="SD";
799+
800+
//set option not to install lib
801+
ConfigurationPreferences.setInstallLibraries(false);
802+
803+
//uninstall lib
804+
LibraryManager.uninstallLibrary( libName);
805+
806+
// create a project that uses a the lib
807+
String testName = "onlyInstallLibraryWhenAllowed";
808+
IProgressMonitor monitor=new NullProgressMonitor();
809+
IPath templateFolder = Shared.getTemplateFolder(testName);
810+
CodeDescription codeDescriptor = CodeDescription.createCustomTemplate(templateFolder);
811+
MCUBoard unoboard = Arduino.uno();
812+
IProject theTestProject = SloeberProject.createArduinoProject(testName, null, unoboard.getBoardDescriptor(), codeDescriptor,
813+
new CompileDescription(), monitor);
814+
//wait for indexer and so on
815+
Shared.waitForAllJobsToFinish();
816+
817+
818+
//Building the project should fail
819+
assertNotNull( Shared.buildAndVerify(theTestProject,3,IncrementalProjectBuilder.FULL_BUILD ,monitor),"Sloeber wrongly installed lib "+libName);
820+
821+
//set option to install libs
822+
ConfigurationPreferences.setInstallLibraries(true);
823+
824+
//trigger the indexer
825+
ICProject cTestProject = CoreModel.getDefault().getCModel().getCProject(theTestProject.getName());
826+
CCorePlugin.getIndexManager().reindex(cTestProject);
827+
Shared.waitForIndexer(theTestProject);
828+
829+
//build should not fail
830+
assertNull( Shared.buildAndVerify(theTestProject,3,IncrementalProjectBuilder.FULL_BUILD ,monitor),"Sloeber dit not install lib "+libName);
831+
832+
833+
834+
}
795835
}

io.sloeber.tests/src/io/sloeber/core/Shared.java

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.eclipse.core.runtime.CoreException;
3232
import org.eclipse.core.runtime.FileLocator;
3333
import org.eclipse.core.runtime.IPath;
34+
import org.eclipse.core.runtime.IProgressMonitor;
3435
import org.eclipse.core.runtime.NullProgressMonitor;
3536
import org.eclipse.core.runtime.Path;
3637
import org.eclipse.core.runtime.Platform;
@@ -259,23 +260,9 @@ public static String buildAndVerifyGivenBuilders(String projectName, BoardDescri
259260
autoDesc.setBuilder(curBuilder);
260261
coreModel.setProjectDescription(theTestProject, projectDescription);
261262

262-
theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
263-
264-
if (hasBuildErrors(theTestProject)!=null) {
265-
Shared.waitForAllJobsToFinish();
266-
Thread.sleep(2000);
267-
theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
268-
if (hasBuildErrors(theTestProject)!=null) {
269-
Shared.waitForAllJobsToFinish();
270-
Thread.sleep(2000);
271-
theTestProject.build(IncrementalProjectBuilder.FULL_BUILD, monitor);
272-
String buildError=hasBuildErrors(theTestProject);
273-
if (buildError!=null) {
274-
myLastFailMessage = myLastFailMessage + NEWLINE +buildError+ NEWLINE+ "Failed to compile the project:" + projectName
275-
+ " with builder " + curBuilder;
276-
}
277-
}
278-
}
263+
buildAndVerify(theTestProject,3,IncrementalProjectBuilder.FULL_BUILD, monitor);
264+
265+
279266

280267
}
281268
if (!myLastFailMessage.isBlank()) {
@@ -295,6 +282,26 @@ public static String buildAndVerifyGivenBuilders(String projectName, BoardDescri
295282
return null;
296283
}
297284

285+
static String buildAndVerify(IProject theTestProject, int maxTries, int buildType, IProgressMonitor monitor) throws Exception {
286+
int curTry = 0;
287+
String buildError=null;
288+
while (curTry++ < maxTries) {
289+
theTestProject.build(buildType, monitor);
290+
Shared.waitForAllJobsToFinish();
291+
Thread.sleep(2000);
292+
buildError = hasBuildErrors(theTestProject);
293+
if (buildError == null) {
294+
return buildError;
295+
}
296+
}
297+
IAutoBuildConfigurationDescription autoDesc = IAutoBuildConfigurationDescription
298+
.getActiveConfig(theTestProject,false);
299+
String builder=autoDesc.getBuilder().getId();
300+
myLastFailMessage = myLastFailMessage + NEWLINE + buildError + NEWLINE + "Failed to compile the project:"
301+
+ theTestProject.getName() + " with builder " + builder;
302+
return buildError;
303+
}
304+
298305
/*
299306
* For some boards that do not run out of the box we know how to fix it. This
300307
* code fixes these things
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "Arduino.h"
2+
#include "SD.h"
3+
//The setup function is called once at startup of the sketch
4+
void setup()
5+
{
6+
// Add your initialization code here
7+
}
8+
9+
// The loop function is called in an endless loop
10+
void loop()
11+
{
12+
//Add your repeated code here
13+
}
14+

0 commit comments

Comments
 (0)