Skip to content

Commit

Permalink
wrapper tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lemonowl committed Sep 13, 2024
1 parent 17d728a commit a8edd5c
Show file tree
Hide file tree
Showing 30 changed files with 303 additions and 121 deletions.
3 changes: 2 additions & 1 deletion python/wrapper/smoke/doc_builder/get_context.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from python.docbuilder import builder
builder.CreateFile("docx")
context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
builder.SaveFile("docx", "BaseExample.docx")
builder.SaveFile("docx", "GetContext.docx")
builder.CloseFile()
2 changes: 1 addition & 1 deletion python/wrapper/smoke/doc_builder/get_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
content[0] = paragraph

document.Call("InsertContent", content)
builder.SaveFile("docx", "BaseExample.docx")
builder.SaveFile("docx", "GetVersion.docx")
builder.CloseFile()
2 changes: 1 addition & 1 deletion python/wrapper/smoke/doc_builder/run_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
oParagraph.AddText("This is a paragraph for RunText");
oDocument.Push(oParagraph);
""")
builder.SaveFile("docx", "Run.docx")
builder.SaveFile("docx", "RunText.docx")
builder.CloseFile()
3 changes: 3 additions & 0 deletions python/wrapper/smoke/doc_builder/save_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from python.docbuilder import builder
builder.CreateFile("docx")
builder.SaveFile("docx", "SaveFile.docx")
2 changes: 1 addition & 1 deletion python/wrapper/smoke/doc_builder/set_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
content[0] = paragraph

document.Call("InsertContent", content)
builder.SaveFile("docx", "ExecuteCommand.docx")
builder.SaveFile("docx", "SetProperty.docx")
builder.CloseFile()
2 changes: 1 addition & 1 deletion python/wrapper/smoke/doc_builder_context/create_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
content[1] = paragraph2
document.Call('InsertContent', content)

builder.SaveFile("docx", "BaseExample.docx")
builder.SaveFile("docx", "CreateArray.docx")
builder.CloseFile()
2 changes: 1 addition & 1 deletion python/wrapper/smoke/doc_builder_context/create_null.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
value = context.CreateNull()
paragraph.Call("AddText", f"Value is null = {value.IsNull()}")

builder.SaveFile("docx", "BaseExample.docx")
builder.SaveFile("docx", "CreateNull.docx")
builder.CloseFile()
14 changes: 14 additions & 0 deletions python/wrapper/smoke/doc_builder_context/create_scope.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
paragraph.Call("AddText", "Without CreateScope script doesn't works")

builder.SaveFile("docx", "CreateScope.docx")
builder.CloseFile()
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
value = context.CreateUndefined()
paragraph.Call("AddText", f"Value is undefined = {value.IsUndefined()}")

builder.SaveFile("docx", "BaseExample.docx")
builder.SaveFile("docx", "CreateUndefined.docx")
builder.CloseFile()
14 changes: 14 additions & 0 deletions python/wrapper/smoke/doc_builder_context/get_global.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
paragraph.Call("AddText", "If this paragraph is here, GetGlobal works")

builder.SaveFile("docx", "GetGlobal.docx")
builder.CloseFile()
15 changes: 15 additions & 0 deletions python/wrapper/smoke/doc_builder_context_scope/close.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
scope.Close()
paragraph.Call("AddText", "Without created scope script doesn't works")

builder.SaveFile("docx", "Close.docx")
builder.CloseFile()
2 changes: 1 addition & 1 deletion python/wrapper/smoke/doc_builder_value/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
paragraph.Call("AddLineBreak")
paragraph.Call("AddText", f"Comment text is {comments.Get(0).Call("GetText").ToString()}")

builder.SaveFile("docx", "IsArray.docx")
builder.SaveFile("docx", "Get.docx")
builder.CloseFile()
14 changes: 4 additions & 10 deletions python/wrapper/smoke/doc_builder_value/is_bool.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
paragraph.Call("AddText", "Some text")
paragraph.Call("AddComment", "Comment one", "John", "uid-1")

comments = document.Call("GetAllComments")
text = comments[0].Call("GetText")
delete = comments[0].Call("Delete")
paragraph.Call("AddLineBreak")
paragraph.Call("AddText", f"Text IsBool = {text.IsBool()}")
track_revisions = document.Call("IsTrackRevisions")
paragraph.Call("AddText", f"Paragraph is bool = {paragraph.IsBool()}")
paragraph.Call("AddLineBreak")
paragraph.Call("AddText", f"Delete result IsBool = {delete.IsBool()}")
paragraph.Call("AddText", f"IsTrackRevisions is bool = {track_revisions.IsBool()}")

builder.SaveFile("docx", "IsArray.docx")
builder.SaveFile("docx", "IsBool.docx")
builder.CloseFile()
20 changes: 20 additions & 0 deletions python/wrapper/smoke/doc_builder_value/is_double.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
image = api.Call("CreateImage",
"https://api.onlyoffice.com/content/img/docbuilder/examples/coordinate_aspects.png",
60 * 36000, 35 * 36000)
paragraph.Call("AddDrawing", image)
paragraph.Call("AddText", f"Width is double = {image.Call("GetWidth").IsDouble()}")
paragraph.Call("AddLineBreak")
paragraph.Call("AddText", f"LockValue is double = {image.Call("GetLockValue").IsDouble()}")

builder.SaveFile("docx", "IsDouble.docx")
builder.CloseFile()
17 changes: 17 additions & 0 deletions python/wrapper/smoke/doc_builder_value/is_empty.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
wrong_call = document.Call("GetElmnt", 0)
paragraph.Call("AddText", f"Right call is empty = {paragraph.IsEmpty()}")
paragraph.Call("AddLineBreak")
paragraph.Call("AddText", f"Wrong call is empty = {wrong_call.IsEmpty()}")

builder.SaveFile("docx", "IsEmpty.docx")
builder.CloseFile()
17 changes: 17 additions & 0 deletions python/wrapper/smoke/doc_builder_value/is_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]
obj = globalObj['Object']

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
paragraph.Call("AddText", f'globalObj["Api"] is undefined = {api.IsFunction()}')
paragraph.Call("AddLineBreak")
paragraph.Call("AddText", f'globalObj["Object"] is undefined = {obj.IsFunction()}')

builder.SaveFile("docx", "IsFunction.docx")
builder.CloseFile()
18 changes: 18 additions & 0 deletions python/wrapper/smoke/doc_builder_value/is_int.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
content = document.Call("GetContent")
count = document.Call("GetElementsCount")
paragraph = document.Call("GetElement", 0)
paragraph.Call("AddText", f"Content is int = {content.IsInt()}")
paragraph.Call("AddLineBreak")
paragraph.Call("AddText", f"ElementsCount is int = {count.IsInt()}")

builder.SaveFile("docx", "IsInt.docx")
builder.CloseFile()
10 changes: 5 additions & 5 deletions python/wrapper/smoke/doc_builder_value/is_null.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
value1 = context.CreateNull()
value2 = context.CreateObject()
paragraph.Call("AddText", f"Value 1 is null = {value.IsNull()}")
text = paragraph.Call("GetText")
style = paragraph.Call("GetStyle")
paragraph.Call("AddText", f"Text is null = {text.IsNull()}")
paragraph.Call("AddLineBreak")
paragraph.Call("AddText", f"Value 2 is null = {value.IsNull()}")
paragraph.Call("AddText", f"Style is null = {style.IsNull()}")

builder.SaveFile("docx", "BaseExample.docx")
builder.SaveFile("docx", "IsNull.docx")
builder.CloseFile()
5 changes: 4 additions & 1 deletion python/wrapper/smoke/doc_builder_value/is_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
paragraph.Call("AddText", f"Global API is object = {api.IsObject()}")
track_revisions = document.Call("IsTrackRevisions")
paragraph.Call("AddText", f"Paragraph is object = {paragraph.IsObject()}")
paragraph.Call("AddLineBreak")
paragraph.Call("AddText", f"IsTrackRevisions is object = {track_revisions.IsObject()}")

builder.SaveFile("docx", "IsObject.docx")
builder.CloseFile()
7 changes: 4 additions & 3 deletions python/wrapper/smoke/doc_builder_value/is_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
paragraph.Call("AddText", "This is IsString method check")
class_type = paragraph.Call("GetClassType")
charts = paragraph.Call("GetAllCharts")
paragraph.Call("AddText", f'ClassType is string = {class_type.IsString()}')
paragraph.Call("AddLineBreak")
paragraph.Call("AddText", f'GetText is string = {paragraph.Call("GetText").IsString()}')
paragraph.Call("GetText")
paragraph.Call("AddText", f'Charts is string = {charts.IsString()}')

builder.SaveFile("docx", "IsString.docx")
builder.CloseFile()
21 changes: 21 additions & 0 deletions python/wrapper/smoke/doc_builder_value/is_undefined.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
image = api.Call("CreateImage",
"https://api.onlyoffice.com/content/img/docbuilder/examples/coordinate_aspects.png",
60 * 36000, 35 * 36000)
paragraph.Call("AddDrawing", image)
images = paragraph.Call("GetAllImages")
paragraph.Call("AddText", f"Images[0] is undefined = {images[0].IsUndefined()}")
paragraph.Call("AddLineBreak")
paragraph.Call("AddText", f"Images[1] is undefined = {images[1].IsUndefined()}")

builder.SaveFile("docx", "IsUndefined.docx")
builder.CloseFile()
2 changes: 1 addition & 1 deletion python/wrapper/smoke/doc_builder_value/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
content.Set(2, paragraph2)
document.Call('InsertContent', content)

builder.SaveFile("docx", "BaseExample.docx")
builder.SaveFile("docx", "Set.docx")
builder.CloseFile()
2 changes: 1 addition & 1 deletion python/wrapper/smoke/doc_builder_value/to_bool.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
paragraph.Call("AddLineBreak")
paragraph.Call("AddText", f"Delete result = {delete.ToBool()}")

builder.SaveFile("docx", "IsArray.docx")
builder.SaveFile("docx", "ToBool.docx")
builder.CloseFile()
18 changes: 18 additions & 0 deletions python/wrapper/smoke/doc_builder_value/to_double.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
paragraph = document.Call("GetElement", 0)
image = api.Call("CreateImage",
"https://api.onlyoffice.com/content/img/docbuilder/examples/coordinate_aspects.png",
60 * 36000, 35 * 36000)
paragraph.Call("AddDrawing", image)
paragraph.Call("AddText", f"Width = {image.Call("GetWidth").ToDouble()}")

builder.SaveFile("docx", "ToDouble.docx")
builder.CloseFile()
16 changes: 16 additions & 0 deletions python/wrapper/smoke/doc_builder_value/to_int.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from python.docbuilder import builder
builder.CreateFile("docx")

context = builder.GetContext()
scope = context.CreateScope()
globalObj = context.GetGlobal()
api = globalObj["Api"]

document = api.Call("GetDocument")
content = document.Call("GetContent")
count = document.Call("GetElementsCount")
paragraph = document.Call("GetElement", 0)
paragraph.Call("AddText", f"ElementsCount = {count.ToInt()}")

builder.SaveFile("docx", "ToInt.docx")
builder.CloseFile()
9 changes: 5 additions & 4 deletions python_spec/wrapper/smoke/doc_builder_context_scope_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

require_relative '../../spec_helper'
describe 'CDocBuilderContextScope tests', :critical do
# it "CDocBuilderContextScope | Close method" do
# docx = builder.build_and_parse('python/wrapper/smoke/doc_builder_context_scope/close.py')
# expect('').to eq('')
# end
it 'CDocBuilderContextScope | Close method' do
temp_script_data = builder.change_output_file('python/wrapper/smoke/doc_builder_context_scope/close.py')
builder.build(temp_script_data[:temp_script_file].path)
expect(File.exist?(temp_script_data[:output_file])).to be(false)
end
end
20 changes: 10 additions & 10 deletions python_spec/wrapper/smoke/doc_builder_context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,28 @@

it 'CDocBuilderContext | CreateNull method' do
docx = builder.build_and_parse('python/wrapper/smoke/doc_builder_context/create_null.py')
expect(docx.elements[0].nonempty_runs[0].text).to eq('Value is null = True')
expect(docx.elements.first.nonempty_runs.first.text).to eq('Value is null = True')
end

# it 'CDocBuilderContext | CreateObject method' do
# docx = builder.build_and_parse('python/wrapper/smoke/doc_builder_context/create_object.py')
# expect('').to eq('')
# end

# it 'CDocBuilderContext | CreateScope method' do
# docx = builder.build_and_parse('python/wrapper/smoke/doc_builder_context/create_scope.py')
# expect('').to eq('')
# end
it 'CDocBuilderContext | CreateScope method' do
docx = builder.build_and_parse('python/wrapper/smoke/doc_builder_context/create_scope.py')
expect(docx.elements.first.nonempty_runs.first.text).to eq("Without CreateScope script doesn't works")
end

it 'CDocBuilderContext | CreateUndefined method' do
docx = builder.build_and_parse('python/wrapper/smoke/doc_builder_context/create_undefined.py')
expect(docx.elements[0].nonempty_runs[0].text).to eq('Value is undefined = True')
expect(docx.elements.first.nonempty_runs.first.text).to eq('Value is undefined = True')
end

# it 'CDocBuilderContext | GetGlobal method' do
# docx = builder.build_and_parse('python/wrapper/smoke/doc_builder_context/get_global.py')
# expect('').to eq('')
# end
it 'CDocBuilderContext | GetGlobal method' do
docx = builder.build_and_parse('python/wrapper/smoke/doc_builder_context/get_global.py')
expect(docx.elements.first.nonempty_runs.first.text).to eq('If this paragraph is here, GetGlobal works')
end

# it 'CDocBuilderContext | IsError method' do
# docx = builder.build_and_parse('python/wrapper/smoke/doc_builder_context/is_error.py')
Expand Down
Loading

0 comments on commit a8edd5c

Please sign in to comment.