顯示具有 iOSdev 標籤的文章。 顯示所有文章
顯示具有 iOSdev 標籤的文章。 顯示所有文章

2015年11月4日 星期三

強大 軟體 自動 測試 工具 SAFS framework open source 多平台 多語言 關鍵字驅動 獨立工具

http://safsdev.sourceforge.net/Default.htm

SAFS
Software Automation Framework Support

Updated 2015.08.25
Initially developed by Carl Nagle for SAS Institute
Evolves as Opensource with permission from SAS Institute

Visit our Software Automation Framwork Support SAFSDEV Project on GitHub.
Visit our Software Automation Framwork Support SAFSDEV Project on SourceForge.


http://www.ibm.com/developerworks/rational/library/09/plainlanguagetestscriptusingsasfwithrft/
Use plain language for test scripts by implementing SAFS with Rational Functional Tester
使用簡單語言來測試軟體,實作SAFS用於IBM® Rational® Functional Tester 功能測試

SAFS framework 特色是
是open source 
多平台
多語言
關鍵字驅動
獨立工具

現在假設你需要測試 一個 ClassicsJavaA
可想而知是個 Java ,你需要JVM (JRE)環境,這裡用1.5.10版

他另外也裝了 MS  Windows Script Host 5.6

安裝SAFS
Install SAFS
To install SAFS:

Go to the SourceForge Web site, and type SAFS in the Search window.
你可以去SourceForge下載相關工具
Click the SAFS page link, and select View all files.
進入頁面 到 選擇 看 全部檔案

Expand SAFSRelease2007.04.18, 
and download the SAFSRelease2007.04.18.ZIP file.
Extract the contents of the~~~~~ SAFSRelease2007.04.18.zip file.
下載 並解壓縮 SAFSRelease2007.04.18.zip 

Double-click the SetupSAFS.wsf script file. SAFS and STAF are installed in these default locations:
執行SetupSAFS.wsf (是 MS  Windows Script Host 批次檔 描述)
會裝到下列路徑
c:\safs
c:\staf
如果想更新 你可以看看" SAFSOverlay \ SAFSOverlay_README.txt "
或是如上述法覆蓋


The SAFS directory structure Give the test project this directory structure:
SAFS 檔案結構如下 

Project_path\Datapool
Project_path\Datapool\Bench
Project_path\Datapool\Dif
Project_path\Datapool\Logs
Project_path\Datapool\Test

舉例你的專案叫   MyTests, SAFS目錄該這樣
For example, if Project_path is c:\MyTest, then the SAFS directory structure is as follows:
C:\MyTests\Datapool
C:\MyTests\Datapool\Bench
C:\MyTests\Datapool\Dif
C:\MyTests\Datapool\Logs
C:\MyTests\Datapool\Test
For additional information and custom installation details, see the SetupSAFS.Readme file that is listed in the Resources section.新增訊息與自訂請看 SetupSAFS.Readme 


Configuring Rational Functional Tester
設置專案去

1. Enable the Java environment in Rational Functional Tester.

2. Run the C:\SAFS\SetupRationalClasspath.WSF script to locate and add IBM Rational JAR files to the CLASSPATH.
在JVM裡要執行當然要在config 寫入java的路徑資訊CLASSPATH
請 執行 C:\SAFS\SetupRationalClasspath.WSF

Important:
Do not name any Rational Functional Tester scripts, "TestScript," because SAFS uses this name. Also make sure that there are no files named:
注意檔名不要與環境檔案衝突

TestScript.java
TestScript.class
TestScriptHelper.class

接著 細節 c:\safs\safstid.ini
[SAFS_LOGS]
AUTOLAUNCH=TRUE
是否預設執行
OVERWRITE=TRUE
是否覆蓋紀錄
CAPXML=TRUE
XML支援

c:\safs\Project\tidtest.ini 
[SAFS_PROJECT]
ProjectRoot="C:\safs\project"
專案名
[SAFS_TEST]
TestName="TIDTest"
測試民
TestLevel="Cycle"
CycleSeparator=","
CycleLogName="TIDTest.SAFS"
紀錄檔名
CycleLogMode="TEXTLOG XMLLOG"
millisBetweenRecords= 0

執行設置 ,執行 runTIDTest.bat , 
java –Dsafs.project.config="c:\safs\project\TIDTEST.ini" org.safs.tools.drivers.SAFSDRIVER pause


Tip: 請確認你的路徑,請停止SAFS 的所有服務與執行工作

If there is an error when the batch file runs, the command prompt displays the error message until you press a key. Without the pause command, the error message is not displayed with sufficient reading time.

Run the runTIDTest.bat file located in C:\safs\Project. 執行批次檔的地方

After the runTIDTest.bat file runs a log named TIDTest.SAFS.txt is generated in C:\safs\Project\Datapool\Logs. The log file contains this message: 
OK TIDTest Services all present and working.



C:\SAFS\Project \ RFTTest.ini 
Edit runRFTTest.bat file, which is the C:\SAFS\Project folder, adding a pause command: 
java –Dsafs.project.config="C:\safs\project\RFTTest.ini" org.safs.tools.drivers.SAFDRIVER pause


確認有 C:\safs\Project\Datapool\Logs \ RFTTest.txt
讀讀 SetupRFT.Readme  

呼 終於完成 configure

 接下來 看看 有哪些 元件

 執行
runTIDTest.bat 
runRFTTest.bat
會有
在 C:\MyTests\Datapool
Cycle table (.CDD file) 循環,記錄完成的大事件
Suite table (.STD file) 確認,Step的大事記
Step table (.SDD file) 步驟,記錄低階 io 與檔案處理
Map file 是RTTI或記憶體內容
四個檔案 
(不過你不用一一自己看,下面有工具)


java 處理緒內容 資訊
The STAF Process Container window
To get the details for the map:

Start the STAF server 在開始功能表,程式集 STAF- Software Testing Automation Framework.
啟動STAF server 
Click Start STAF, and then minimize the command prompt that opens.
會有常駐圖示

執行批次檔   C:\safs\Project \ STAFProcessContainer.bat
  
開啟執行 STAF Process Container window 


本文 省略一些 註解 請看原文



Test Automation Frameworks




REFERENCES:
How Do I...?









2015年10月21日 星期三

本篇文主要是實作 AVAudioSession bluetooth support, 你需要去看看 iOS audio API

http://devmonologue.com/ios/tutorials/avaudiosession-bluetooth-support/

AVAudioSession bluetooth support

本篇文主要是實作  AVAudioSession bluetooth support,
你需要去看看 iOS audio API


Adding bluetooth to an AVAudioSession involves several features as far as I’m concerned. Lets go through them all:

Enabling bluetooth audio
First of all, you need to specifically instruct AVAudioSession that you allow sound to be routed to bluetooth devices. This can be done while setting your audio category:

[session setCategory:AVAudioSessionCategoryPlayAndRecord 
         withOptions:AVAudioSessionCategoryOptionAllowBluetooth
               error:&error];


Remember, your audio session category tells iOS how you plan on using sound within your app. For instance, AVAudioSessionCategoryPlayAndRecord means that you want to both play and record audio. Anyway, what we are interested in, is the options parameter. By adding AVAudioSessionCategoryOptionAllowBluetooth, we allow iOS to play our app’s audio on a bluetooth audio device.

Note: I’ve seen projects where a category is set on an AVAudioSession in multiple places. If I’ve learned anything about audio in iOS is that you don’t use setCategory: lightly! In fact, in most cases you should only set is once. Why? For one thing it is a complex operation. If it’s executed on the main thread, it will make your UI unresponsive for a second. But more importantly, setting the category all over the place might lead into strange behavior – you will never know when audio will be going to the speaker or the earphone…

Switching between audio routes
When you are implementing AVAudioSession bluetooth support, you will probably want to be able to switch between audio devices. And there doesn’t seem to be a clearly defined way to do that in the documentation.

There are several ways to do it. However, what I found to be the best working one is setting the preferred audio input. Here are some examples:



2015年10月17日 星期六

iPhone iOS 藍芽 支援 AVAudioSession 音響 切換 耳機


iPhone iOS 藍芽 支援 音響 切換 耳機

AVAudioSession bluetooth support
 December 17, 2014  Nikola Sobadjiev
Adding Bluetooth audio support to an iOS app 

[session setCategory:AVAudioSessionCategoryPlayAndRecord 
         withOptions:AVAudioSessionCategoryOptionAllowBluetooth
               error:&error]; 

Switching to bluetooth

- (AVAudioSessionPortDescription*)bluetoothAudioDevice
{
    NSArray* bluetoothRoutes = @[AVAudioSessionPortBluetoothA2DP, AVAudioSessionPortBluetoothLE, AVAudioSessionPortBluetoothHFP];
    return [self audioDeviceFromTypes:bluetoothRoutes];
}

- (AVAudioSessionPortDescription*)builtinAudioDevice
{
    NSArray* builtinRoutes = @[AVAudioSessionPortBuiltInMic];
    return [self audioDeviceFromTypes:builtinRoutes];
}

- (AVAudioSessionPortDescription*)speakerAudioDevice
{
    NSArray* builtinRoutes = @[AVAudioSessionPortBuiltInSpeaker];
    return [self audioDeviceFromTypes:builtinRoutes];
}

- (AVAudioSessionPortDescription*)audioDeviceFromTypes:(NSArray*)types
{
    NSArray* routes = [[AVAudioSession sharedInstance] availableInputs];
    for (AVAudioSessionPortDescription* route in routes)
    {
        if ([types containsObject:route.portType])
        {
            return route;
        }
    }
    return nil;
}

- (BOOL)switchBluetooth:(BOOL)onOrOff
{
    NSError* audioError = nil;
    BOOL changeResult = NO;
    if (onOrOff == YES)
    {
        AVAudioSessionPortDescription* _bluetoothPort = [self bluetoothAudioDevice];
        changeResult = [[AVAudioSession sharedInstance] setPreferredInput:_bluetoothPort
                                                     error:&audioError];
    }
    else
    {
        AVAudioSessionPortDescription* builtinPort = [self builtinAudioDevice];
        changeResult = [[AVAudioSession sharedInstance] setPreferredInput:builtinPort
                                                     error:&audioError];
    }
    return changeResult;
}
Wow, that was a lot of code! Well, the important bit is setting the preferred input in the last method. The other code is just to get the right AVAudioSessionPortDescription object for speaker, earphone or bluetooth.

Switching to speaker
While there are other way to do that, this is what I prefer to use:

- (BOOL)switchSpeaker:(BOOL)onOrOff
{
    NSError* audioError = nil;
    BOOL changeResult = NO;
    if (onOrOff == YES)
    {
        changeResult = [[AVAudioSession sharedInstance] overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker
                                                           error:&audioError];
    }
    else
    {
        AVAudioSessionPortDescription* builtinPort = [self builtinAudioDevice];
        changeResult = [[AVAudioSession sharedInstance] setPreferredInput:builtinPort
                                                                    error:&audioError];
    }
    return changeResult;
}
Switching to earpiece
This one is easy. It’s just the opposite of switching to speaker:

- (BOOL)switchEarphone:(BOOL)onOrOff
{
    return [self switchSpeaker:!onOrOff];
}

AVAudioSession bluetooth support can be a daunting task. And there isn't much information about it in the internet. I hope this article helps you with your task. Thanks for reading!
Share this:
Share
Related Posts:

Text to speech in iOS – AVSpeechSynthesizer tutorial 

UIPageViewController tutorial 

NSURLProtocol tutorial
Tutorials AVAudioSession, bluetooth, ios, Objective-C
Post navigation
← DevMonologue has a new lookTop articles for 2014 →
10 thoughts on “AVAudioSession bluetooth support”

 S
- February 16, 2015 at 4:37 pm
builtinAudioDevice is used in switchSpeaker? And speakerAudioDevice isn’t used. Are you sure this is ok?

Reply
 Nikola Sobadjiev
- February 17, 2015 at 3:22 pm
Yes, it should be OK. We cannot use speakerAudioDevice to go to speaker in switchSpeaker. That’s because we rely on the setPreferredInput:error: method to switch the audio device. However, it sets the preferred input. And the speaker is an output, not input. In fact, the earpiece and the speaker use the same input device – the built-in mic.

In my testing the only reliable way to go to the speaker is via the overrideOutputAudioPort:error: method and AVAudioSessionPortOverrideSpeaker.

Reply
 Jakob Olsen
- March 6, 2015 at 7:11 am
Hi, great post.

Would it be possible to make the audio route from builtin Microphone to bluetooth headset ?
if how yes could ou be so kind and show me in an example ?

Br
Jakob

Reply
 Nikola Sobadjiev
- March 9, 2015 at 11:41 am
Doesn’t the sample code in the article work? It should be something like:

NSArray* bluetoothRoutes = @[AVAudioSessionPortBluetoothA2DP, AVAudioSessionPortBluetoothLE, AVAudioSessionPortBluetoothHFP];
AVAudioSessionPortDescription* _bluetoothPort = [self audioDeviceFromTypes:bluetoothRoutes];
changeResult = [[AVAudioSession sharedInstance] setPreferredInput:_bluetoothPort
error:&audioError];

Reply
 Stas
- April 7, 2015 at 10:30 pm
Hi
Is it possible to make bluetooth mic for input and device speaker for output?

Or they still didn’t changed this rule?
Moreover, selecting a Bluetooth HFP output using the MPVolumeView’s route picker will automatically change the input to the Bluetooth HFP input. Therefore both the input and output will always end up on the Bluetooth HFP device even though only the input or output was set individually.

Thx

Reply
 Nikola Sobadjiev
- April 10, 2015 at 1:46 pm
I personally haven’t tried to achieve that, but it seems that every time you change either the input or output, iOS changes the audio device altogether.

Reply
 Subrata Laha
- August 4, 2015 at 5:12 am
Hi , anyone have tried the same problem (bluetooth mic for input and device speaker for output) ? Please let me know , thanks in advance .

Reply
 Nikola Sobadjiev
- August 4, 2015 at 8:23 am
I don’t think you’ll be able to achieve this with AVAudioSession. If you really need to implement that feature, you’ll probably have to use CoreBluetooth and handle things from a really low level.

Reply
 raja
- April 20, 2015 at 2:45 pm
i am doing music app.

this is my stackoverflow link about my problem

http://stackoverflow.com/questions/29740589/ios-how-to-play-buffering-audio-in-bluetooth-headset-in-my-music-app

i applied your code. now my doubt is

when we need to call these below methods?
– (BOOL)switchBluetooth:(BOOL)onOrOff
– (BOOL)switchEarphone:(BOOL)onOrOff
– (BOOL)switchSpeaker:(BOOL)onOrOff


Reply

Nikola Sobadjiev
- April 22, 2015 at 8:30 am
Normally, you’d call one of these methods in response to a user action. When you support multiple audio sources, you’d want to allow your users to choose between them at runtime.

You can call them reliably even after playback has started. They’ll still change the audio device.

In your case, provided that you always what the audio to go through the bluetooth headset, you’d want to call switchBluetooth: before starting your audio, but after you activate the audio session and set the category via the setCategory: method of AVAudioSession

Reply