Skip to content

Commit 7813df1

Browse files
authored
Merge pull request #267 from cchampet/testLog
pyTest: added tests to check log and options
2 parents faff281 + a7eefbe commit 7813df1

File tree

6 files changed

+147
-16
lines changed

6 files changed

+147
-16
lines changed

src/AvTranscoder/Library.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef _AV_TRANSCODER_DESCRIPTION_HPP_
22
#define _AV_TRANSCODER_DESCRIPTION_HPP_
33

4-
#include "common.hpp"
4+
#include <AvTranscoder/common.hpp>
55

66
#include <vector>
77
#include <string>

src/AvTranscoder/Option.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class AvExport Option
5050

5151
// flags
5252
int getFlags() const { return _avOption->flags; }
53-
bool isEncodingOpt() const { return (_avOption->flags & AV_OPT_FLAG_ENCODING_PARAM) == AV_OPT_FLAG_ENCODING_PARAM; }
54-
bool isDecodingOpt() const { return (_avOption->flags & AV_OPT_FLAG_DECODING_PARAM) == AV_OPT_FLAG_DECODING_PARAM; }
55-
bool isAudioOpt() const { return (_avOption->flags & AV_OPT_FLAG_AUDIO_PARAM) == AV_OPT_FLAG_AUDIO_PARAM; }
56-
bool isVideoOpt() const { return (_avOption->flags & AV_OPT_FLAG_VIDEO_PARAM) == AV_OPT_FLAG_VIDEO_PARAM; }
57-
bool isSubtitleOpt() const { return (_avOption->flags & AV_OPT_FLAG_SUBTITLE_PARAM) == AV_OPT_FLAG_SUBTITLE_PARAM; }
53+
bool isEncodingOpt() const { return (getFlags() & AV_OPT_FLAG_ENCODING_PARAM) == AV_OPT_FLAG_ENCODING_PARAM; }
54+
bool isDecodingOpt() const { return (getFlags() & AV_OPT_FLAG_DECODING_PARAM) == AV_OPT_FLAG_DECODING_PARAM; }
55+
bool isAudioOpt() const { return (getFlags() & AV_OPT_FLAG_AUDIO_PARAM) == AV_OPT_FLAG_AUDIO_PARAM; }
56+
bool isVideoOpt() const { return (getFlags() & AV_OPT_FLAG_VIDEO_PARAM) == AV_OPT_FLAG_VIDEO_PARAM; }
57+
bool isSubtitleOpt() const { return (getFlags() & AV_OPT_FLAG_SUBTITLE_PARAM) == AV_OPT_FLAG_SUBTITLE_PARAM; }
5858

5959
// get default value
6060
bool getDefaultBool() const;

src/AvTranscoder/avTranscoder.i

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,14 @@
1616
%include "AvTranscoder/swig/avSeek.i"
1717
%include "AvTranscoder/swig/avOperator.i"
1818

19-
%{
20-
#include <AvTranscoder/log.hpp>
21-
%}
22-
19+
%include "AvTranscoder/log.i"
20+
%include "AvTranscoder/library.i"
21+
%include "AvTranscoder/option.i"
22+
%include "AvTranscoder/util.i"
2323
%include "AvTranscoder/progress/progress.i"
2424
%include "AvTranscoder/properties/properties.i"
2525
%include "AvTranscoder/profile/profile.i"
2626
%include "AvTranscoder/data/data.i"
27-
28-
%include <AvTranscoder/log.hpp>
29-
30-
%include "AvTranscoder/library.i"
31-
%include "AvTranscoder/option.i"
32-
%include "AvTranscoder/util.i"
3327
%include "AvTranscoder/codec/codec.i"
3428
%include "AvTranscoder/stream/stream.i"
3529
%include "AvTranscoder/decoder/decoder.i"

src/AvTranscoder/log.i

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
%{
2+
#include <AvTranscoder/common.hpp>
3+
#include <AvTranscoder/log.hpp>
4+
%}
5+
6+
%include <AvTranscoder/common.hpp>
7+
%include <AvTranscoder/log.hpp>

test/pyTest/testLog.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import os
2+
from nose.tools import *
3+
4+
from pyAvTranscoder import avtranscoder as av
5+
6+
7+
def _logMessages(logger):
8+
"""
9+
Local function to log several messages.
10+
"""
11+
logger.log(av.AV_LOG_DEBUG, 'This is a debug message!')
12+
logger.log(av.AV_LOG_INFO, 'This is an info message!')
13+
logger.log(av.AV_LOG_WARNING, 'This is a warning message!')
14+
logger.log(av.AV_LOG_ERROR, 'This is an error message!')
15+
16+
17+
def testLogInFile():
18+
"""
19+
Check the behavior of the logger file.
20+
"""
21+
logger = av.Logger()
22+
# log several messages in the standard output
23+
_logMessages(logger)
24+
25+
# redirect the output of the logging messages
26+
logger.logInFile()
27+
# the logger message should exist and be empty
28+
assert_equals(os.stat(av.LOG_FILE).st_size, 0)
29+
30+
# log several messages in the logger file
31+
_logMessages(logger)
32+
# the logger message should exist and be filled
33+
assert_greater(os.stat(av.LOG_FILE).st_size, 0)

test/pyTest/testOption.py

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import os
2+
3+
# Check if environment is setup to run the tests
4+
if os.environ.get('AVTRANSCODER_TEST_AUDIO_WAVE_FILE') is None or \
5+
os.environ.get('AVTRANSCODER_TEST_AUDIO_MOV_FILE') is None:
6+
from nose.plugins.skip import SkipTest
7+
raise SkipTest("Need to define environment variables "
8+
"AVTRANSCODER_TEST_AUDIO_WAVE_FILE and "
9+
"AVTRANSCODER_TEST_AUDIO_MOV_FILE")
10+
11+
from nose.tools import *
12+
13+
from pyAvTranscoder import avtranscoder as av
14+
15+
16+
@raises(IndexError)
17+
def testAccessOfUnknownAudioCodecOptions():
18+
"""
19+
Check access to an unknown codec option.
20+
"""
21+
optionName = 'a'
22+
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
23+
inputFile = av.InputFile(inputFileName)
24+
audioProperties = inputFile.getProperties().getAudioProperties()[0]
25+
26+
audioProperties.getCodecOption(optionName)
27+
28+
29+
def testAccessOfKnownCodecOptionInAudioStream():
30+
"""
31+
Check access to a known codec option from an audio stream.
32+
"""
33+
optionName = 'b'
34+
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_WAVE_FILE']
35+
inputFile = av.InputFile(inputFileName)
36+
audioProperties = inputFile.getProperties().getAudioProperties()[0]
37+
38+
option = audioProperties.getCodecOption(optionName)
39+
40+
# common attributes
41+
assert_equals(option.getName(), optionName)
42+
assert_equals(option.getHelp(), 'set bitrate (in bits/s)')
43+
assert_equals(option.getType(), av.eOptionBaseTypeInt)
44+
assert_greater(option.getOffset(), 0)
45+
assert_equals(option.getMin(), 0.0)
46+
assert_greater(option.getMax(), 0.0)
47+
assert_greater(option.getMax(), 0.0)
48+
49+
# flags
50+
assert_equals(option.isEncodingOpt(), True)
51+
assert_equals(option.isDecodingOpt(), False)
52+
assert_equals(option.isAudioOpt(), True)
53+
assert_equals(option.isVideoOpt(), True)
54+
assert_equals(option.isSubtitleOpt(), False)
55+
56+
# value
57+
assert_equals(option.getInt(), audioProperties.getBitRate())
58+
assert_equals(option.getDefaultInt(), 200000) # see AV_CODEC_DEFAULT_BITRATE
59+
60+
# childs
61+
assert_equals(option.hasChild(), False)
62+
assert_equals(len(option.getChilds()), 0)
63+
64+
65+
def testAccessOfKnownCodecOptionInVideoStream():
66+
"""
67+
Check access to a known codec option from a video stream.
68+
"""
69+
optionName = 'flags'
70+
inputFileName = os.environ['AVTRANSCODER_TEST_AUDIO_MOV_FILE']
71+
inputFile = av.InputFile(inputFileName)
72+
videoProperties = inputFile.getProperties().getVideoProperties()[0]
73+
74+
option = videoProperties.getCodecOption(optionName)
75+
76+
# common attributes
77+
assert_equals(option.getName(), optionName)
78+
assert_equals(option.getUnit(), optionName)
79+
assert_equals(option.getType(), av.eOptionBaseTypeGroup)
80+
81+
# flags
82+
assert_equals(option.isEncodingOpt(), True)
83+
assert_equals(option.isDecodingOpt(), True)
84+
assert_equals(option.isAudioOpt(), True)
85+
assert_equals(option.isVideoOpt(), True)
86+
assert_equals(option.isSubtitleOpt(), True)
87+
88+
# value
89+
assert_equals(option.getInt(), 0)
90+
assert_equals(option.getDefaultInt(), 0)
91+
92+
# childs
93+
assert_equals(option.hasChild(), True)
94+
assert_greater(len(option.getChilds()), 0)
95+
# check if all the childs have a name
96+
for child in option.getChilds():
97+
assert_greater(len(child.getName()), 0)

0 commit comments

Comments
 (0)