-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add nativefilestream and several new methods to
File
and `FileStrea…
…m` (#98)
- Loading branch information
1 parent
27cd682
commit aaf1815
Showing
25 changed files
with
3,143 additions
and
842 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
105 changes: 105 additions & 0 deletions
105
System.IO.FileSystem.UnitTests/FileSystemUnitTestsBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// | ||
// Copyright (c) .NET Foundation and Contributors | ||
// See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using nanoFramework.System.IO.FileSystem; | ||
using nanoFramework.TestFramework; | ||
using System.Threading; | ||
|
||
namespace System.IO.FileSystem.UnitTests | ||
{ | ||
[TestClass] | ||
public abstract class FileSystemUnitTestsBase | ||
{ | ||
///////////////////////////////////////////////////////////////////// | ||
// The test execution can be configured using the following fields // | ||
///////////////////////////////////////////////////////////////////// | ||
|
||
// set to the number of drives available in the target | ||
internal const int _numberOfDrives = 1; | ||
|
||
// set to the root of the drive to use for the tests | ||
// D: SD card | ||
// E: USB mass storage | ||
// I: and J: internal flash | ||
internal const string Root = @"I:\"; | ||
|
||
// set to true to wait for removable drive(s) to be mounted | ||
internal const bool _waitForRemovableDrive = false; | ||
|
||
// set to true to have SPI SD card mounted | ||
internal const bool _configAndMountSdCard = false; | ||
|
||
////////////////////////////////////////////////// | ||
|
||
private SDCard _mycardBacking; | ||
|
||
internal SDCard MyCard | ||
{ | ||
set | ||
{ | ||
_mycardBacking = value; | ||
} | ||
|
||
get | ||
{ | ||
_mycardBacking ??= InitializeSDCard(); | ||
|
||
return _mycardBacking; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Initializes the SD card. Can be overridden in the derived class to provide specific initialization. | ||
/// </summary> | ||
/// <returns></returns> | ||
protected SDCard InitializeSDCard() | ||
{ | ||
// Example initialization logic | ||
SDCard.SDCardMmcParameters parameters = new SDCard.SDCardMmcParameters | ||
{ | ||
dataWidth = SDCard.SDDataWidth._4_bit, | ||
enableCardDetectPin = true, | ||
cardDetectPin = 21 | ||
}; | ||
|
||
return new SDCard(parameters); | ||
} | ||
|
||
/// <summary> | ||
/// Helper method to be called from the tests to handle removable drives. | ||
/// </summary> | ||
internal void RemovableDrivesHelper() | ||
{ | ||
if (_configAndMountSdCard) | ||
{ | ||
TryToMountAgain: | ||
|
||
try | ||
{ | ||
MyCard.Mount(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
OutputHelper.WriteLine($"SDCard mount failed: {ex.Message}"); | ||
|
||
Thread.Sleep(TimeSpan.FromSeconds(2)); | ||
|
||
MyCard = null; | ||
|
||
goto TryToMountAgain; | ||
} | ||
} | ||
|
||
if (_waitForRemovableDrive) | ||
{ | ||
// wait until all removable drives are mounted | ||
while (DriveInfo.GetDrives().Length < _numberOfDrives) | ||
{ | ||
Thread.Sleep(1000); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.