# Use cases from apps

This document collects use cases from different pc-apps (how device-lib-js is used)

### PROGRAMMER App

**TODO (late 2022):** Create test cases for  IMEI programming for 91DK (will be implemented in the future);

#### List of use cases (8/13):
1) \+ Test that error_code property exists (not ErrorCode)
   <br>`// @ts-expect-error To be fixed in nrfdl
   if (error.error_code === 0x25b) {`
2) \+ Test Progress callback (that expected object) with CallbackParameters: firmwareProgram() - program CB
3) progressCallback() -> get progress.operation === 'erase_image'
4) Test firmwareProgram(getDeviceLibContext(), device.id, 'NRFDL_FW_FILE', firmwareFormat, dfuFilePath as string, completeCallback, progressCallback); 
5) \+ Test deviceControlGetProtectionStatus()
        fix type in nrfdl: snake_case -> get protection_status (snake case)
6) \+ Get DeviceCore object
7) \+ firmwareRead(getDeviceLibContext(), deviceId, 'NRFDL_FW_BUFFER','NRFDL_FW_INTEL_HEX', completeCb, () => {}, null, ...) -- jLink
8) \+ deviceControlRecover()
9) firmwareProgram(getDeviceLibContext(), deviceId, 'NRFDL_FW_BUFFER', 'NRFDL_FW_INTEL_HEX', Buffer.from(hexFileString, 'utf8'), ...)
10) \+ deviceControlReset()
11) \+ if (protectionStatus === 'NRFDL_PROTECTION_STATUS_NONE') getDeviceCoreInfo()
12) Test Modem firmwareProgram(getDeviceLibContext(), deviceId, 'NRFDL_FW_FILE', 'NRFDL_FW_NRF91_MODEM', fileName, completeCallback, progressCallback)
13) Test MCUBoot nrfdl.firmwareProgram(getDeviceLibContext(), device.id, 'NRFDL_FW_FILE',  firmwareFormat, dfuFilePath as string, ...)
14) _Postponed:_ "Support 53 Devices in DTM" - task name from trello -> write tests for device 53


### SHARED (App) Library


#### List of use cases (10/11):
1) \+ createContext(), enumerate()
2) Test firmwareProgram( getDeviceLibContext(), device.id, 'NRFDL_FW_BUFFER' 'NRFDL_FW_SDFU_ZIP', zipBuffer,...)
3) \+ getModuleVersions() (check if applies to different devices?)
4) \+ get SerialPort[]
5) \+ readFwInfo();
6) \+ firmwareProgram(): NRFDL_FW_BUFFER + NRFDL_FW_INTEL_HEX && NRFDL_FW_FILE + NRFDL_FW_INTEL_HEX
7) \+ setLogLevel(context, verboseLogging ? 'NRFDL_LOG_TRACE' : 'NRFDL_LOG_ERROR')
8) \+ setLogPattern(getDeviceLibContext(), '[%n][%l](%T.%e) %v');
9) \+ setTimeoutConfig(getDeviceLibContext(), { enumerateMs: 3 * 60 * 1000 })
10) \+ startLogEvents() & stopLogEvents()
11) \+ startHotPlugEvents() & stopHotPlugEvents();


### OTHER

#### List of use cases (4/7):
1) \+ firmwareRead() - progress callback - test types because they were updated for firmwareWrite -> there may be a conflict
2) \+ createContext() with special characters
3) \+ create multiple contexts
4) \+ program firmware with the file which includes unicode & special characters
5) (require DK53) get device core info for DK 53 with NRFDL_DEVICE_CORE_APPLICATION core and NETWORK core
6) firmwareRead() - pass exact params as on these lines (last params null, null, coreInfo.name) https://github.com/NordicSemiconductor/pc-nrfconnect-programmer/blob/582462a4fbd822c3654fcc1ec900996b4cbfea49/src/actions/jlinkTargetActions.ts#L225
7) Use nrf-intel-hex for validating buffer from fwRead() 