Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
6872be24
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
6872be24
编写于
9月 17, 2015
作者:
A
Andy Gocke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add more tests.
上级
d1ec9ff7
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
84 addition
and
20 deletion
+84
-20
src/Compilers/CSharp/Test/Emit/Emit/ResourceTests.cs
src/Compilers/CSharp/Test/Emit/Emit/ResourceTests.cs
+33
-0
src/Compilers/Core/CodeAnalysisTest/InternalUtilities/StreamExtensionsTests.cs
...deAnalysisTest/InternalUtilities/StreamExtensionsTests.cs
+13
-0
src/Compilers/Core/CodeAnalysisTest/PEWriter/BlobTests.cs
src/Compilers/Core/CodeAnalysisTest/PEWriter/BlobTests.cs
+18
-1
src/Compilers/Core/Portable/PEWriter/ManagedResource.cs
src/Compilers/Core/Portable/PEWriter/ManagedResource.cs
+2
-1
src/Test/Utilities/Shared/Mocks/TestStream.cs
src/Test/Utilities/Shared/Mocks/TestStream.cs
+18
-18
未找到文件。
src/Compilers/CSharp/Test/Emit/Emit/ResourceTests.cs
浏览文件 @
6872be24
...
...
@@ -13,6 +13,7 @@
using
Microsoft.CodeAnalysis.Test.Utilities
;
using
Roslyn.Test.Utilities
;
using
Xunit
;
using
System.Globalization
;
namespace
Microsoft.CodeAnalysis.CSharp.UnitTests.Emit
{
...
...
@@ -878,5 +879,37 @@ public static void Main()
Assert
.
Equal
(
expected
,
versionData
);
}
[
Fact
]
public
void
ResourceProviderStreamGivesBadLength
()
{
var
backingStream
=
new
MemoryStream
(
new
byte
[]
{
1
,
2
,
3
,
4
});
var
stream
=
new
TestStream
(
readFunc
:
backingStream
.
Read
,
length
:
6
,
// Lie about the length (> backingStream.Length)
getPosition
:
()
=>
backingStream
.
Position
);
var
c1
=
CreateCompilationWithMscorlib
(
""
);
var
tmpCulture
=
CultureInfo
.
CurrentUICulture
;
try
{
Thread
.
CurrentThread
.
CurrentUICulture
=
CultureInfo
.
InvariantCulture
;
var
result
=
c1
.
Emit
(
new
MemoryStream
(),
manifestResources
:
new
[]
{
new
ResourceDescription
(
"res"
,
()
=>
stream
,
false
)
});
result
.
Diagnostics
.
Verify
(
// error CS1566: Error reading resource 'res' -- 'Resource stream ended at 4 bytes, expected 6 bytes.'
Diagnostic
(
ErrorCode
.
ERR_CantReadResource
).
WithArguments
(
"res"
,
"Resource stream ended at 4 bytes, expected 6 bytes."
).
WithLocation
(
1
,
1
));
}
finally
{
Thread
.
CurrentThread
.
CurrentUICulture
=
tmpCulture
;
}
}
}
}
src/Compilers/Core/CodeAnalysisTest/InternalUtilities/StreamExtensionsTests.cs
浏览文件 @
6872be24
...
...
@@ -105,5 +105,18 @@ public void ExceptionMayChangePosition()
Assert
.
Throws
<
IOException
>(()
=>
stream
.
TryReadAll
(
destArray
,
0
,
sourceArray
.
Length
));
Assert
.
Equal
(
2
,
backingStream
.
Position
);
}
[
Fact
]
public
void
PrematureEndOfStream
()
{
var
sourceArray
=
new
byte
[]
{
1
,
2
,
3
,
4
};
var
stream
=
new
MemoryStream
(
sourceArray
);
var
destArray
=
new
byte
[
6
];
// Try to read more bytes than exist in the stream
Assert
.
Equal
(
4
,
stream
.
TryReadAll
(
destArray
,
0
,
6
));
var
expected
=
new
byte
[]
{
1
,
2
,
3
,
4
,
0
,
0
};
Assert
.
Equal
(
expected
,
destArray
);
}
}
}
src/Compilers/Core/CodeAnalysisTest/PEWriter/BlobTests.cs
浏览文件 @
6872be24
...
...
@@ -877,7 +877,24 @@ public void ProperStreamRead()
});
var
builder
=
PooledBlobBuilder
.
GetInstance
(
sourceArray
.
Length
);
builder
.
TryWriteBytes
(
stream
,
sourceArray
.
Length
);
Assert
.
Equal
(
sourceArray
.
Length
,
builder
.
TryWriteBytes
(
stream
,
sourceArray
.
Length
));
Assert
.
Equal
(
sourceArray
,
builder
.
ToArray
());
builder
.
Free
();
}
[
Fact
]
public
void
PrematureEndOfStream
()
{
var
sourceArray
=
new
byte
[]
{
1
,
2
,
3
,
4
};
var
stream
=
new
MemoryStream
(
sourceArray
);
var
destArray
=
new
byte
[
6
];
var
builder
=
PooledBlobBuilder
.
GetInstance
(
destArray
.
Length
);
// Try to write more bytes than exist in the stream
Assert
.
Equal
(
4
,
builder
.
TryWriteBytes
(
stream
,
6
));
Assert
.
Equal
(
sourceArray
,
builder
.
ToArray
());
builder
.
Free
();
...
...
src/Compilers/Core/Portable/PEWriter/ManagedResource.cs
浏览文件 @
6872be24
...
...
@@ -6,6 +6,7 @@
using
System.IO
;
using
Microsoft.CodeAnalysis
;
using
Roslyn.Utilities
;
using
System.Globalization
;
namespace
Microsoft.Cci
{
...
...
@@ -52,7 +53,7 @@ public void WriteData(BlobBuilder resourceWriter)
if
(
bytesWritten
!=
count
)
{
throw
new
EndOfStreamException
(
string
.
Format
(
CodeAnalysisResources
.
ResourceStreamEndedUnexpectedly
,
bytesWritten
,
count
));
string
.
Format
(
C
ultureInfo
.
CurrentUICulture
,
C
odeAnalysisResources
.
ResourceStreamEndedUnexpectedly
,
bytesWritten
,
count
));
}
resourceWriter
.
Align
(
8
);
}
...
...
src/Test/Utilities/Shared/Mocks/TestStream.cs
浏览文件 @
6872be24
...
...
@@ -8,13 +8,19 @@ namespace Roslyn.Test.Utilities
public
class
TestStream
:
Stream
{
private
readonly
bool
_canRead
,
_canSeek
,
_canWrite
;
private
Func
<
byte
[],
int
,
int
,
int
>
_readFunc
;
private
readonly
Func
<
byte
[],
int
,
int
,
int
>
_readFunc
;
private
readonly
long
_length
;
private
readonly
Func
<
long
>
_getPosition
;
private
readonly
Action
<
long
>
_setPosition
;
public
TestStream
(
bool
canRead
=
false
,
bool
canSeek
=
false
,
bool
canWrite
=
false
,
Func
<
byte
[],
int
,
int
,
int
>
readFunc
=
null
)
Func
<
byte
[],
int
,
int
,
int
>
readFunc
=
null
,
long
length
=
0
,
Func
<
long
>
getPosition
=
null
,
Action
<
long
>
setPosition
=
null
)
{
_canRead
=
canRead
;
_canSeek
=
canSeek
;
...
...
@@ -22,6 +28,13 @@ public class TestStream : Stream
_readFunc
=
readFunc
!=
null
?
readFunc
:
(
_1
,
_2
,
_3
)
=>
{
throw
new
NotImplementedException
();
};
_length
=
length
;
_getPosition
=
getPosition
!=
null
?
getPosition
:
()
=>
{
throw
new
NotImplementedException
();
};
_setPosition
=
setPosition
!=
null
?
setPosition
:
(
_1
)
=>
{
throw
new
NotImplementedException
();
};
}
public
override
bool
CanRead
=>
_canRead
;
...
...
@@ -30,25 +43,12 @@ public class TestStream : Stream
public
override
bool
CanWrite
=>
_canWrite
;
public
override
long
Length
{
get
{
throw
new
NotSupportedException
();
}
}
public
override
long
Length
=>
_length
;
public
override
long
Position
{
get
{
throw
new
NotSupportedException
();
}
set
{
throw
new
NotSupportedException
();
}
get
{
return
_getPosition
();
}
set
{
_setPosition
(
value
);
}
}
public
override
void
Flush
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录